繁体   English   中英

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

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

几周后,RedHat 发布了JBoss EAP 7.1.0 ,因此我开始对我们的应用程序(EAR with Model (JPA)、EJB (CDI) 和 Web)进行一些初步测试。 我们最近使用了 EAP 7.0.7 – 所以版本差距相当小。

只用了几秒钟就遇到了第一个大问题。 现在,每当我们尝试调用接口提供的default实现时,WELD 都会抛出org.jboss.weld.exceptions.UnsupportedOperationException而没有任何附加消息。 为什么不支持接口的默认实现?

注意:接口实现了这个方法......它不是空的方法声明!

以下是此类接口的示例:

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

一个实现该接口的简单 bean:

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

一个简单的 UI 管理器类:

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

以及引用该方法的 xhtml:

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

这会引发以下缩短的堆栈跟踪:

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

这只是一个简单的例子。 我对接口提供的许多其他默认方法都有这种影响。 WeldSubclass将不再处理那些对 EAP 7.0.7 和更早版本没有问题的实现。

一旦我在MyFeature覆盖该方法,这些异常就消失了。

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

我们的应用程序使用了几个这样的默认接口实现,并由数百个实现这些接口的类组成。 有没有其他实用的方法来解决这个问题,然后根本避免使用默认接口实现?

PS :请记住, WeldSubclass是 WELD 应用的代理,而不是我自己的类。 与合法的 EAP 7.0.7 相比,EAP 7.1.0 的较新 WELD 实现引发了异常。 甚至没有用任何额外的信息来解释例外情况,这些信息可能会为这种意外变化提供一些原因。

所以事实证明,我遇到了https://issues.jboss.org/browse/WELD-2407 ,这是用 WELD v2.4.5.Final 解决的——EAP v7.1.0 和 v7.1.1 仍然使用 WELD v2.4.3 (红帽)。

用 WELD v2.4.6.Final 修补 EAP v7.1.1 解决了它。 但不幸的是,我将不得不等待正式的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM