arquillian / arquillian-extension-jacoco

Arquillian Jacoco Extension
28 stars 30 forks source link

java.io.IOException: invalid constant type: 17 at 128 #84

Closed epomatti closed 4 years ago

epomatti commented 4 years ago

Java: openjdk 11.0.8 2020-07-14 WildFly: 20.0.1.Final OS: Ubuntu 20.04

I'm getting this error when adding the Jacoco extension and running my tests with mvn test:

Aug 18, 2020 8:12:36 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 5.0.0.Final
Aug 18, 2020 8:12:36 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.5.1.Final
Aug 18, 2020 8:12:36 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.5.1.Final
Aug 18, 2020 8:12:36 PM org.wildfly.security.Version <clinit>
INFO: ELY00001: WildFly Elytron version 1.1.0.Final
Aug 18, 2020 8:12:38 PM org.jboss.as.arquillian.container.ArchiveDeployer undeploy
WARN: Failed to undeploy test.war: {"WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => "WFLYCTL0216: Management resource '[(\"deployment\" => \"test.war\")]' not found"}}
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.674 s <<< FAILURE! - in solid.domains.employee.EmployeeRepositoryTestCase
[ERROR] solid.domains.employee.EmployeeRepositoryTestCase  Time elapsed: 4.603 s  <<< ERROR!
org.jboss.arquillian.container.spi.client.container.DeploymentException: 
Cannot deploy test.war: {"WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"test.war#test\".__FIRST_PHASE__" => "org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile
    Caused by: org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile
    Caused by: java.io.IOException: invalid constant type: 17 at 128"}}}}

My arquillian.xml

I tried removing the Hibernate lib but it didn't do any effect:

<extension qualifier="jacoco">
    <property name="excludes">org.**;com.**</property>
    <property name="includes">solid.**</property>
    <property name="appendAsmLibrary">false</property>
</extension>

My pom.xml profile:

               <profile>
            <id>wildfly-remote</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.wildfly.arquillian</groupId>
                    <artifactId>wildfly-arquillian-container-remote</artifactId>
                    <version>2.1.1.Final</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jacoco</groupId>
                    <artifactId>org.jacoco.core</artifactId>
                    <version>0.8.5</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>org.jboss.arquillian.extension</groupId>
                    <artifactId>arquillian-jacoco</artifactId>
                    <version>1.1.0</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.8.5</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

This is the complete stacktrace:

20:26:55,183 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 102) MSC000001: Failed to start service jboss.persistenceunit."test.war#test".__FIRST_PHASE__: org.jboss.msc.service.StartException in service jboss.persistenceunit."test.war#test".__FIRST_PHASE__: org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile
    at org.jboss.as.jpa@20.0.1.Final//org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl$1$1.run(PhaseOnePersistenceUnitServiceImpl.java:128)
    at org.jboss.as.jpa@20.0.1.Final//org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl$1$1.run(PhaseOnePersistenceUnitServiceImpl.java:104)
    at org.wildfly.security.elytron-private@1.12.1.Final//org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:658)
    at org.jboss.as.jpa@20.0.1.Final//org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl$1.run(PhaseOnePersistenceUnitServiceImpl.java:137)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
    at java.base/java.lang.Thread.run(Thread.java:834)
    at org.jboss.threads@2.3.3.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile
    at org.hibernate@5.3.17.Final//org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassFile(ClassFileArchiveEntryHandler.java:64)
    at org.hibernate@5.3.17.Final//org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.handleEntry(ClassFileArchiveEntryHandler.java:47)
    at org.hibernate.jipijapa-hibernate5-3@20.0.1.Final//org.jboss.as.jpa.hibernate5.VirtualFileSystemArchiveDescriptor.processVirtualFile(VirtualFileSystemArchiveDescriptor.java:94)
    at org.hibernate.jipijapa-hibernate5-3@20.0.1.Final//org.jboss.as.jpa.hibernate5.VirtualFileSystemArchiveDescriptor.processVirtualFile(VirtualFileSystemArchiveDescriptor.java:69)
    at org.hibernate.jipijapa-hibernate5-3@20.0.1.Final//org.jboss.as.jpa.hibernate5.VirtualFileSystemArchiveDescriptor.processVirtualFile(VirtualFileSystemArchiveDescriptor.java:69)
    at org.hibernate.jipijapa-hibernate5-3@20.0.1.Final//org.jboss.as.jpa.hibernate5.VirtualFileSystemArchiveDescriptor.processVirtualFile(VirtualFileSystemArchiveDescriptor.java:69)
    at org.hibernate.jipijapa-hibernate5-3@20.0.1.Final//org.jboss.as.jpa.hibernate5.VirtualFileSystemArchiveDescriptor.visitArchive(VirtualFileSystemArchiveDescriptor.java:49)
    at org.hibernate@5.3.17.Final//org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:47)
    at org.hibernate@5.3.17.Final//org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:76)
    at org.hibernate@5.3.17.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:99)
    at org.hibernate@5.3.17.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:240)
    at org.hibernate@5.3.17.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:168)
    at org.hibernate@5.3.17.Final//org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:32)
    at org.hibernate@5.3.17.Final//org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:89)
    at org.hibernate.jipijapa-hibernate5-3@20.0.1.Final//org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.<init>(TwoPhaseBootstrapImpl.java:39)
    at org.hibernate.jipijapa-hibernate5-3@20.0.1.Final//org.jboss.as.jpa.hibernate5.HibernatePersistenceProviderAdaptor.getBootstrap(HibernatePersistenceProviderAdaptor.java:252)
    at org.jboss.as.jpa@20.0.1.Final//org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl.createContainerEntityManagerFactoryBuilder(PhaseOnePersistenceUnitServiceImpl.java:254)
    at org.jboss.as.jpa@20.0.1.Final//org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl.access$900(PhaseOnePersistenceUnitServiceImpl.java:59)
    at org.jboss.as.jpa@20.0.1.Final//org.jboss.as.jpa.service.PhaseOnePersistenceUnitServiceImpl$1$1.run(PhaseOnePersistenceUnitServiceImpl.java:125)
    ... 9 more
Caused by: java.io.IOException: invalid constant type: 17 at 128
    at org.javassist//javassist.bytecode.ConstPool.readOne(ConstPool.java:1355)
    at org.javassist//javassist.bytecode.ConstPool.read(ConstPool.java:1279)
    at org.javassist//javassist.bytecode.ConstPool.<init>(ConstPool.java:198)
    at org.javassist//javassist.bytecode.ClassFile.read(ClassFile.java:794)
    at org.javassist//javassist.bytecode.ClassFile.<init>(ClassFile.java:185)
    at org.hibernate@5.3.17.Final//org.hibernate.boot.archive.scan.spi.ClassFileArchiveEntryHandler.toClassFile(ClassFileArchiveEntryHandler.java:61)
    ... 27 more
famod commented 4 years ago

Have you already tried https://github.com/arquillian/arquillian-extension-jacoco#maven-setup-with-shaded-asm-and-jacoco-core?

epomatti commented 4 years ago

@famod I was trying it right now, it didn't work:

<dependency>
    <groupId>org.jboss.arquillian.extension</groupId>
    <artifactId>arquillian-jacoco-with-asm</artifactId>
    <version>1.1.0</version>
    <scope>test</scope>
</dependency>

appendAsmLibrary set to true

    <extension qualifier="jacoco">
        <property name="excludes">org.**;com.**</property>
        <property name="includes">solid.**</property>
        <property name="appendAsmLibrary">true</property>
    </extension>
famod commented 4 years ago

Hm, seems the javassist version used by Hibernate 5.3.17.Final is too old: https://github.com/jboss-javassist/javassist/issues/270 (3.23.2-GA according to https://mvnrepository.com/artifact/org.hibernate/hibernate-core/5.3.17.Final)

epomatti commented 4 years ago

I tried this but it didn't work. Should it?

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.3.17.Final</version>
    <exclusions>
        <exclusion>
                        <groupId>org.javassist</groupId>
                        <artifactId>javassist</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.27.0-GA</version>
</dependency>
famod commented 4 years ago

This is not so easy for WildFly. You'll have to (try to) update the javassist module in the server. Since even Hibernate 5.4 is still on javassist 3.24.0 (and 3.26.0 is required), the question arises whether Hibernate 5.3 is compatible with javassist 3.26.0+ at all...

epomatti commented 4 years ago

Yeah I came to the same conclusion here, too much time away from WildFly... I'll have to change the module.

Even Hibernate 6 is not yet using javassist 3.26.0, so not even that is an option.

epomatti commented 4 years ago

Reported it to them: https://hibernate.atlassian.net/browse/HHH-14158

Can you think of any other alternative to get coverage with Arquillian and WildFly? I could run JaCoCo in another server like Glassfish, OpenLiberty, etc.

bartoszmajsak commented 4 years ago

Thanks a lot @famod for stepping up and helping @epomatti!

vivagif-Za8SR94o41BvKO2efz

Zlika commented 4 years ago

I have the same kind of error when my build runs on our jenkins server (running maven 3.5.3 and openjdk 11.0.2) but it works without any problem on my local computer (debian 10 running maven 3.6 and openjdk 11.0.8). How is it possible?? I'm using wildfly 20.0.1, arquillian 1.7.0.Alpha4 and arquillian-jacoco 1.1.0.

famod commented 4 years ago

@Zlika Hm, maybe related to the minor JDK version difference, but I doubt it. The Maven version is even less likely. You could try using 11.0.2 locally or vice versa (11.0.8 on jenkins).

Zlika commented 4 years ago

@famod I tried to reproduce the bug on my computer with openjdk 11.0.2 and maven 3.5.3 (to have a similar configuration than my jenkins server) and I cannot reproduce the bug! So it must be linked to the jenkins server itself in a way or another.

fabrii commented 4 years ago

I'm having the same issue. I also tried to exclude the Wildfly Javassit module with jboss-deployment-structure.xml but with no luck. If you find a solution please let me know!

Thank you.

Zlika commented 4 years ago

Hi @fabrii . Based on @famod analysis I made a workaround. Here is my test setup (including the workaround):

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <id>integration-test</id>
                <goals><goal>integration-test</goal></goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <!-- Download and unzip Wildfly in target folder for integration tests -->
              <execution>
                <id>unpack</id>
                <phase>pre-integration-test</phase>
                <goals><goal>unpack</goal></goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.wildfly</groupId>
                      <artifactId>wildfly-dist</artifactId>
                      <version>${wildfly.version}</version>
                      <type>zip</type>
                      <overWrite>false</overWrite>
                      <outputDirectory>${project.build.directory}</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
              <!-- We have to configure the maven-dependency-plugin to copy the necessary dependencies to the target folder.
                   These libraries will be assembled into the war-archive by ShrinkWrap once we run the test.  -->
              <execution>
                <id>copy-test-libs</id>
                <phase>pre-integration-test</phase>
                <goals><goal>copy-dependencies</goal></goals>
                <configuration>
                  <stripVersion>true</stripVersion>
                  <outputDirectory>${project.build.directory}/test-libs</outputDirectory>
                  <includeScope>runtime</includeScope>
                  <useSubDirectoryPerScope>true</useSubDirectoryPerScope>
                </configuration>
              </execution>
    <!--
     Workaround for bug https://github.com/arquillian/arquillian-extension-jacoco/issues/84.
     This bug only occurs during the build on the Jenkins server, not on my computer (?!?).
     The workaround is to upgrade the javassist-3.23.2-GA.jar Wildfly module used by Hibernate
     to version 3.26.0-GA which fixes https://github.com/jboss-javassist/javassist/issues/270.
     This workaround only applies to (and is only needed with) the Wildfly instance used for integration tests.
    -->
              <!-- Step 1: add new javassist-3.26.0-GA.jar file in the Wildfly distribution used for integration tests -->
              <execution>
                <id>copy-javassist</id>
                <phase>pre-integration-test</phase>
                <goals><goal>copy</goal></goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.javassist</groupId>
                      <artifactId>javassist</artifactId>
                      <version>3.26.0-GA</version>
                      <type>jar</type>
                      <outputDirectory>${project.build.directory}/wildfly-${wildfly.version}/modules/system/layers/base/org/javassist/main</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <phase>pre-integration-test</phase>
                <goals><goal>run</goal></goals>
                <configuration>
                  <target>
                    <!-- Step 2: remove Wildfly built-in javassist module -->
                    <delete>
                      <fileset dir="${project.build.directory}/wildfly-${wildfly.version}/modules/system/layers/base/org/javassist/main" includes="javassist-3.23.2-GA.jar"/>
                    </delete>
                    <!-- Step 3: patch Wildfly javassist's module.xml file to use the new version of the artifact -->
                    <replace token="javassist-3.23.2-GA.jar" value="javassist-3.26.0-GA.jar" dir="${project.build.directory}/wildfly-${wildfly.version}/modules/system/layers/base/org/javassist/main">
                      <include name="module.xml"/>
                    </replace>
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
    <!-- End of workaround -->
fabrii commented 4 years ago

@Zlika I'm actually using a remote wildfly instance for IT, so I only had to replace the library in the modules folder without changing my pom.xml. I prefer this approach so the IT server can be always up. I thought that replacing that library was going to mess things up with hibernate but it actually worked! I did some tests with search and save operations without problems.

Thank you!

hantsy commented 3 years ago

@Zlika if possible to exclude javassist module in the jboss-deployment descriptor, and include a copy of javassist in the project deps.