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

标签 java interface jboss-weld

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

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

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

以下是此类接口(interface)的示例:

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

实现该接口(interface)的简单 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

这只是一个简单的例子。我对接口(interface)提供的许多其他默认方法都有这种效果。 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();
    }
}

我们的应用程序使用其中几个默认接口(interface)实现,并由数百个实现这些接口(interface)的类组成。 除了完全避免默认接口(interface)实现之外,还有什么实际方法可以解决这个问题吗?

PS:请记住,WeldSubclass 是 WELD 应用的代理,而不是我自己的类。与 EAP 7.0.7 相比,EAP 7.1.0 的较新 WELD 实现引发了该异常,在 EAP 7.0.7 中这是合法的。并且甚至没有用任何可能给出意外变化的原因的附加信息来解释该异常。

最佳答案

原来我遇到了https://issues.jboss.org/browse/WELD-2407这是通过 WELD v2.4.5.Final 解决的 - EAP v7.1.0 和 v7.1.1 仍然使用 WELD v2.4.3 (redhat)。

用 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 /] 

关于java - 即使我的接口(interface)带有默认方法实现,为什么 WELD 仍会抛出 UnsupportedOperationException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49106511/

相关文章:

java - 带有阿拉伯字符的drawString-java

c# - 任何人都可以帮我解决有关 C# 中的接口(interface)的问题

java - 在 JBoss 7 部署结束时执行操作

java - 奇怪的未经检查的转换警告

java - 使用 @Produces 注释时出现不明确的依赖关系

eclipse - 在 Java EE 开发中快速周转的理想设置是什么?

java - 使用 Docker 安装 rJava 包

java - SimpleDateFormat 解析的行为是否不同?

java - Hibernate select id of join column without join

c - C 的结构化模块接口(interface)