testcontainers-java: Exception NoClassDefFoundError org/testcontainers/utility/PathUtils
Hello
There is an exception in MountableFile, it does not find the class PathUtils when it calls recursiveDeleteDir from shutdownHook. I think this is because during the shutdown hook the class loader is already closed by Maven and cannot be used to load new classes.
See attached stack trace
Exception in thread "Thread-17" java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils$1
at org.testcontainers.utility.PathUtils.recursiveDeleteDir(PathUtils.java:26)
at org.testcontainers.utility.MountableFile.lambda$deleteOnExit$0(MountableFile.java:284)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassNotFoundException: org.testcontainers.utility.PathUtils$1
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
... 3 more
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 34 (10 by maintainers)
I just re-opened the issue, since it is clearly amplified by https://github.com/testcontainers/testcontainers-jooq-codegen-maven-plugin,
Maybe I don’t understand something, but why then have this plugin in the first place? Plugin repo (also testcontainers) - https://github.com/testcontainers/testcontainers-jooq-codegen-maven-plugin The official how-to page also refers it: https://testcontainers.com/guides/working-with-jooq-flyway-using-testcontainers/
Looks like a big inconsistency to me.
As anybody can see in the comments here, this issue is not fixed and should be reopened. It was closed by some clean-up script because it was stale.
I use the latest version of testcontainers and can reproduce this issue on every Maven run:
src/test/application.properties:
pom.xml:
Output of ‘./mvnw verify’:
Steps to reproduce:
I’m happy to provide more information if needed.
Did anyone ever find a solution to this issue? I also get the error with jOOQ+flyway.
Note, I only seem to get it when TESTCONTAINERS_RYUK_DISABLED=true, which is required on Bitbucket Pipelines.
@Auriium shutdown hooks are an essential part of JVM, and
NoClassDefFoundErroris caused by Maven, not Testcontainers.However, you can call
ResourceReaper.instance().stopAndRemoveContainer(...)after you finished with it. This way, it will be removed from the set of containers scheduled for removal, and the shutdown hook won’t load any classes.