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

Classloading error with QuarkusMock regression in 1.12.0.CR1 #14991

Closed
vsevel opened this issue Feb 11, 2021 · 10 comments · Fixed by #15092
Closed

Classloading error with QuarkusMock regression in 1.12.0.CR1 #14991

vsevel opened this issue Feb 11, 2021 · 10 comments · Fixed by #15092
Labels
env/windows Impacts Windows machines kind/bug Something isn't working
Milestone

Comments

@vsevel
Copy link
Contributor

vsevel commented Feb 11, 2021

Describe the bug
I upgraded from 1.11.2 to 1.12.0.CR1, and I get the following error in my unit tests:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.123 s <<< FAILURE! - in com.xx.arte.ocpdeploy.deploy.noreg.DeployNoRegFtuTest
[ERROR] com.xx.arte.ocpdeploy.deploy.noreg.DeployNoRegFtuTest.noreg  Time elapsed: 1.327 s  <<< ERROR!
java.lang.ClassCastException: class org.mockito.codegen.VaultSystemBackendEngine$MockitoMock$192437934 cannot be cast to class io.quarkus.vault.runtime.VaultSystemBackendManager (org.mockito.codegen.VaultSystemBackendEngine$MockitoMock$192437934 is in
unnamed module of loader net.bytebuddy.dynamic.loading.MultipleParentClassLoader @36d1793a; io.quarkus.vault.runtime.VaultSystemBackendManager is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @6b08b323)
        at com.xx.arte.ocpdeploy.deploy.noreg.DeployNoRegFtuTest.noreg(DeployNoRegFtuTest.java:21)

I don't have a stacktrace other than the line of the test.

Expected behavior
No regression. Mock works as expected.

Actual behavior
The unit test fails with the above exception.

To Reproduce
I don't have yet an independent reproducer. Here is the code in my application that is causing the issue:

    @BeforeAll
    public static void mockVaultSystemBackendEngine() {

        VaultSystemBackendEngine sys = Mockito.mock(VaultSystemBackendEngine.class);
        VaultHealthStatus vaultHealthStatus = new VaultHealthStatus();
        vaultHealthStatus.setInitialized(true);
        Mockito.when(sys.healthStatus()).thenReturn(vaultHealthStatus);
        QuarkusMock.installMockForType(sys, VaultSystemBackendEngine.class);
    }

Environment (please complete the following information):

  • Output of uname -a or ver: Microsoft Windows [Version 10.0.17763.1697]
  • Output of java -version: openjdk version "11.0.1-redhat" 2018-10-16 LTS
  • GraalVM version (if different from Java): N/A
  • Quarkus version or git rev: 1.12.0.CR1
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
@vsevel vsevel added the kind/bug Something isn't working label Feb 11, 2021
@ghost ghost added the env/windows Impacts Windows machines label Feb 11, 2021
@gsmet
Copy link
Member

gsmet commented Feb 11, 2021

/cc @stuartwdouglas

@stuartwdouglas
Copy link
Member

Any chance you could test with this PR: #14952

@vsevel
Copy link
Contributor Author

vsevel commented Feb 11, 2021

it is actually not easy to recompile quarkus in our corporate env. is there any snapshot version I could use?

@vsevel
Copy link
Contributor Author

vsevel commented Feb 11, 2021

I was able to make a build with your branch. unfortunately it does not solve the issue.

@stuartwdouglas
Copy link
Member

I just added this same code to VaultTest in the Quarkus codebase and there was no exception. Can you add System.out.println(Thread.currentThread().getContextClassLoader()); to the top of the method to see what the current ClassLoader is, it should be: QuarkusClassLoader:Quarkus Base Runtime ClassLoader

@vsevel
Copy link
Contributor Author

vsevel commented Feb 12, 2021

I added a trace in the BeforeAll, and before using the mock in the business code, both are showing QuarkusClassLoader:Quarkus Base Runtime ClassLoader
I will try to create a reproducer out of my code today.

@vsevel
Copy link
Contributor Author

vsevel commented Feb 12, 2021

@vsevel
Copy link
Contributor Author

vsevel commented Feb 15, 2021

any news on this issue? is the reproducer badly coded, or do we have a real problem?

@stuartwdouglas
Copy link
Member

Mockito.mock(VaultSystemBackendEngine.class); needs to be Mockito.mock(VaultSystemBackendManager.class). You also likey need the PR I linked above.

I will add something to detect this.

stuartwdouglas added a commit to stuartwdouglas/quarkus that referenced this issue Feb 15, 2021
@quarkus-bot quarkus-bot bot added this to the 1.13 - master milestone Feb 16, 2021
@vsevel
Copy link
Contributor Author

vsevel commented Feb 16, 2021

I confirm the suggested fix worked out.
and I did not need the PR linked above BTW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants