Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure on JDK11 with PowerMock + JaCoCo offline instrumentation #1017

Closed
nilson-aguiar opened this issue Oct 11, 2019 · 16 comments · Fixed by #1041
Closed

Test failure on JDK11 with PowerMock + JaCoCo offline instrumentation #1017

nilson-aguiar opened this issue Oct 11, 2019 · 16 comments · Fixed by #1041

Comments

@nilson-aguiar
Copy link

nilson-aguiar commented Oct 11, 2019

Steps to reproduce

PowerMock version:
JaCoCo version: 0.8.4
Operating system: used this docker image maven:3-jdk-11-slim
Tool integration: Maven

Expected behaviour

Complete code coverage equally on different JDK's

Actual behaviour

Tests breaking on JDK11 and working ok with JDK8

I've created a repository to show the problem. I know that the integration between PowerMock and JaCoCo needs to work with offline instrumentation (in some cases) and I've created a test project to try it. So I got these results:

  • On branch master uses java11 with online instrumentation. The code coverage on DummyService is 15%

  • On branch java8 uses java8 with offline instrumentation. The code coverage on DummyService is 100%

  • On branch java11 uses java11 with offline instrumentation. The tests are broken with the error bellow:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.368 s <<< FAILURE! - in br.com.testing.jacocoerror.service.DummyServiceTest
[ERROR] initializationError(br.com.testing.jacocoerror.service.DummyServiceTest)  Time elapsed: 0.01 s  <<< ERROR!
java.lang.IllegalStateException: Failed to transform class with name br.com.testing.jacocoerror.service.DummyServiceTest. Reason: java.io.IOException: invalid constant type: 17 at 49
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 17 at 49
Caused by: java.io.IOException: invalid constant type: 17 at 49

I've created the same issue inntially on JaCoCo's repository and as explained there the issue is thrown by PowerMock

https://github.com/powermock/powermock/blob/powermock-2.0.3/powermock-core/src/main/java/org/powermock/core/classloader/javassist/JavassistMockClassLoader.java#L119

@valfirst
Copy link
Contributor

The error comes from Javassist. PowerMock uses javassistVersion = "3.25.0-GA", the described issue was fixed and released in javassist 3.26.0-GA (jboss-javassist/javassist#270). However it is still not fully compatible with JDK 11, one more issue was found: jboss-javassist/javassist#282.

@nilson-aguiar
Copy link
Author

based on your answer and the fact that javaassist 3.26.0-GA is released, do you know if there is any powermock's released planned to update to 3.26 from javaassist?

@valfirst
Copy link
Contributor

jboss-javassist/javassist#282 is fixed and merged to master branch: jboss-javassist/javassist@559bc90.
New release of Javassist is required, then PowerMock can be updated to make it fully-compatible with JaCoCo 0.8.4 + JDK 11.

@nilson-aguiar
Copy link
Author

thanks for the quick reply!

@rhysowen9
Copy link

Looks like the fix for jboss-javassist/javassist#282 has now been included in the latest release at 3.27.0-GA. Is there scope for this issue to be picked back up?

@rhysowen9
Copy link

Thanks for your work both.
@thekingn0thing , I don't know much about PowerMock's release cadence. Are you able to advise when we might see a release that includes #1041 ?

@valfirst
Copy link
Contributor

@rhysowen9 the release is already published, it's2.0.6

@rhysowen9
Copy link

🤦‍♂ Didn't get the release email. My bad, thanks again for your work 💪

@arushi315
Copy link

Hi @valfirst is this issue only for offline instructions?
We recently moved to Java 11 and seeing coverage reported as 0.
We are on Powermock version 2.0.7 and Jacoco version 0.8.5.

Using this example for reporting- https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven/maven-multimodule

@valfirst
Copy link
Contributor

Using this example for reporting- https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven/maven-multimodule

Did it work before migration to Java 11?

@arushi315
Copy link

Hi @valfirst,
Thank you for your quick response.
Yes, I was able to get the coverage but now coverage is 0.

Able to see coverage with:
Java 8
Powermock: 1.7.4
Jacoco: 0.8.5
Following structure described in - https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven/maven-multimodule

When we moved from Java 8 to Java 11, we update PowerMock version and also moved from powermock-api-mockito to powermock-api-mockito2, Mockito-all to Mockito-core.

@valfirst
Copy link
Contributor

@arushi315 I believe you should migrate to powermock-api-mockito2 at first, and then migrate from JDK 8 to JDK 11

@arushi315
Copy link

Sure @valfirst I can give that a try but ultimately we want to move to JDK11.
Do you suggest trying offline instructions in that case?

@valfirst
Copy link
Contributor

I recommend to migrate with small steps and check the state at each step:

  • upgrade mockito + powermock > check coverage
  • migrate to JDK 11 > check coverage

@arushi315
Copy link

arushi315 commented Jun 2, 2021

HI @valfirst,
Sorry its been some time for this issue.
I got some time today to circle back on this and I did some testing.

Coverage is generated with Java 8 with the following versions:
Jacoco: 0.8.6
Powermock: 2.0.2
mockito-core: 3.3.3

Maven dependencies:

         <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.core.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-reflect</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito2</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.agent</artifactId>
            <version>${jacoco.version}</version>
            <scope>test</scope>
        </dependency>

The same fails with Java 11.

With Java 8 although coverage is generated, it still does not create the coverage for test classes using powermock.

Is there anything you recommend checking?

@arushi315
Copy link

Hi @valfirst just following up on this, if you got a chance to take a look?
Again sorry that I commented on this late.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants