简体   繁体   English

即使我的接口带有默认方法实现,为什么 WELD 仍会抛出 UnsupportedOperationException?

[英]Why does WELD throw an UnsupportedOperationException even though my interface comes with default method implementations?

A few days weeks RedHat released JBoss EAP 7.1.0 and so I've started to do some first tests with our application (EAR with Model (JPA), EJB (CDI) and Web).几周后,RedHat 发布了JBoss EAP 7.1.0 ,因此我开始对我们的应用程序(EAR with Model (JPA)、EJB (CDI) 和 Web)进行一些初步测试。 We've used EAP 7.0.7 recently – so the version gap is rather small.我们最近使用了 EAP 7.0.7 – 所以版本差距相当小。

It took only a few seconds to run into the first major problem.只用了几秒钟就遇到了第一个大问题。 WELD now throws an org.jboss.weld.exceptions.UnsupportedOperationException without any additional message whenever we try to call a default implementation provided by an interface.现在,每当我们尝试调用接口提供的default实现时,WELD 都会抛出org.jboss.weld.exceptions.UnsupportedOperationException而没有任何附加消息。 Why are default implementations from interfaces not supported?为什么不支持接口的默认实现?

NOTE: The interface implements this method... it's not the empty method declaration!注意:接口实现了这个方法......它不是空的方法声明!

Here is an example for such an interface:以下是此类接口的示例:

public interface Feature {
    default boolean desiresNewConversation() {
        return false;
    }
}

A simple bean implementing that interface:一个实现该接口的简单 bean:

@Named
public class MyFeature implements Feature, Serializable {
    public String getName() {
        return "Example";
    }
    // Class does NOT override the default method of the interface.
}

A simple manager class for the UI:一个简单的 UI 管理器类:

@Named
public class FeatureManager implements Serializable {
    public void start(Feature f) {
        // ...
    }
    public String propagation(Feature f) {
        return f.desiresNewConversation() ? "none" : "join";
    }
}

And the xhtml referencing that method:以及引用该方法的 xhtml:

<h:form>
    <h:commandButton value="#{myFeature.name}" action="#{featureManager.start(myFeature)}">
        <f:param name="conversationPropagation" value="#{featureManager.propagation(myFeature)}" />
    </h:commandButton>
</h:form>

This throws the following shortened stacktrace:这会引发以下缩短的堆栈跟踪:

Caused by: org.jboss.weld.exceptions.UnsupportedOperationException: 
    at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:49)
    at my.package.MyFeature$Proxy$_$$_WeldSubclass.desiresNewConversation(Unknown Source)
    at my.package.FeatureManager.propagation(FeatureManage.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at javax.el.ELUtil.invokeMethod(ELUtil.java:311)
    ... 107 more

This is only a simple example.这只是一个简单的例子。 I'm having this effect on many other default methods provided by interfaces.我对接口提供的许多其他默认方法都有这种影响。 The WeldSubclass won't handle those implementations anymore which made no problem with EAP 7.0.7 and earlier versions. WeldSubclass将不再处理那些对 EAP 7.0.7 和更早版本没有问题的实现。

As soon as I override that method in MyFeature those exceptions are gone.一旦我在MyFeature覆盖该方法,这些异常就消失了。

@Named
public class MyFeature implements Feature {
    public String getName() {
        return "Example";
    }
    @Override
    public boolean desiresNewConversation() {
        return Feature.super.desiresNewConversation();
    }
}

Our application uses several of these default interface implementations and consists of many hundreds of classes implementing those interfaces.我们的应用程序使用了几个这样的默认接口实现,并由数百个实现这些接口的类组成。 Is there any practical way to solve this other then avoiding default interface implementations at all?有没有其他实用的方法来解决这个问题,然后根本避免使用默认接口实现?

PS : Keep in mind that WeldSubclass is a proxy applied by WELD and not my own class. PS :请记住, WeldSubclass是 WELD 应用的代理,而不是我自己的类。 The exception is thrown by the newer WELD implementation of EAP 7.1.0 compared to EAP 7.0.7 where this was legit.与合法的 EAP 7.0.7 相比,EAP 7.1.0 的较新 WELD 实现引发了异常。 And the exception is not even explained with any additional information that might give some reasons for that unexpected change.甚至没有用任何额外的信息来解释例外情况,这些信息可能会为这种意外变化提供一些原因。

So it turns out that I've run into https://issues.jboss.org/browse/WELD-2407 which is solved with WELD v2.4.5.Final – EAP v7.1.0 and v7.1.1 still use WELD v2.4.3 (redhat).所以事实证明,我遇到了https://issues.jboss.org/browse/WELD-2407 ,这是用 WELD v2.4.5.Final 解决的——EAP v7.1.0 和 v7.1.1 仍然使用 WELD v2.4.3 (红帽)。

Patching EAP v7.1.1 with WELD v2.4.6.Final solved it.用 WELD v2.4.6.Final 修补 EAP v7.1.1 解决了它。 But unfortunately I'll have to wait for an official EAP release.但不幸的是,我将不得不等待正式的 EAP 版本。

localhost:JBoss-EAP-7.1 daniel$ bin/jboss-cli.sh 
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[standalone@localhost:9990 /] patch apply /Users/daniel/Downloads/wildfly-11.0.0.Final-weld-2.4.6.Final-patch.zip --override-all
{
    "outcome" : "success",
    "response-headers" : {
        "operation-requires-restart" : true,
        "process-state" : "restart-required"
    }
}
[standalone@localhost:9990 /] 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在接口默认方法中抛出异常 - Throw exception in interface default method 为什么我的 IDE 说我的一段代码没有扩展其超类的方法,即使它是? - Why does my IDE say my piece of code isnt extending a method of its superclass, even though it is? 为什么我的方法抛出NoSuchMethodError? - Why does my method throw a NoSuchMethodError? 为什么我的方法说它必须返回一个类型字符串并给我一个错误,即使我的方法确实返回一个类型字符串 - Why does my method say it must return a type string and gives me an error even though my method does return a type string 具有UnsupportedOperationException实现的默认方法 - Default method with UnsupportedOperationException implementation 即使条件为真,为什么我的方法仍返回假? - Why is my method returning false even though the conditions are true? JAXB为什么说“ xxx是一个接口,而JAXB无法处理接口”。 即使生成的类不是接口 - Why does JAXB say “xxx is an interface, and JAXB can't handle interfaces”. Even though the generated class is not an interface 为什么我的递归方法使我的程序抛出 InvalidClassException? - Why does my recursive method make my program throw an InvalidClassException? 为什么这个类编译即使它没有正确实现其接口? - Why does this class compile even though it does not properly implement its interface? 为什么我的applet的paint方法抛出ConcurrentModificationException - Why does my applet's paint method throw a ConcurrentModificationException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM