wildflycdijava-17jboss-weldweld-junit5

weld-junit5 with Java 17


Is it possible to run weld-junit5 with Java 17? We are using Wildfly 26 with Java 17.

When I run a Unit test I get an exception:

org.jboss.weld.exceptions.WeldException: WELD-001524: Unable to load proxy class for bean Managed Bean [class de.XXX] with qualifiers [@Any @Default] with class class de.XXX using classloader jdk.internal.loader.ClassLoaders$AppClassLoader@2aae9190
...
    at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:370)
Caused by: java.lang.ExceptionInInitializerError
    at org.jboss.weld.bean.proxy.ProxyFactory.createProxyClass(ProxyFactory.java:469)
    at org.jboss.weld.bean.proxy.ProxyFactory.getProxyClass(ProxyFactory.java:362)
    ... 68 more
Caused by: java.lang.RuntimeException: cannot initialize ClassPool
    at org.jboss.weld.util.bytecode.ClassFileUtils.<clinit>(ClassFileUtils.java:71)
    ... 70 more
Caused by: java.lang.NoSuchFieldException: override
    at java.base/java.lang.Class.getDeclaredField(Class.java:2610)
    at org.jboss.weld.util.bytecode.ClassFileUtils$1.run(ClassFileUtils.java:59)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
    at org.jboss.weld.util.bytecode.ClassFileUtils.<clinit>(ClassFileUtils.java:48)
    ... 70 more

I tried to run a JUnit test with weld-junit5 in versions 2.0.2, 3.0.0.Final and 4.0.0.Final and always get above exception.


Solution

  • I solved it by defining the weld-se-core lib for the tests:

    <dependency>
        <groupId>org.jboss.weld.se</groupId>
        <artifactId>weld-se-core</artifactId>
        <version>3.1.9.Final</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.weld</groupId>
        <artifactId>weld-junit5</artifactId>
        <version>2.0.2.Final</version>
        <scope>test</scope>
    </dependency>
    

    No it is running with Java 17! Also see https://github.com/weld/weld-testing/issues/157 for more details.