testcontainers-jooq-codegen-maven-plugin icon indicating copy to clipboard operation
testcontainers-jooq-codegen-maven-plugin copied to clipboard

java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils

Open avasenin opened this issue 1 year ago • 14 comments

Version of plugin 0.0.3 Version of jooq: 3.18.7 Version of testcontainers: 1.19.3

This error appeared all the time, even in case of successful runs.

Can be related to https://github.com/testcontainers/testcontainers-java/issues/1454

Exception in thread "Thread-5" java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils
	at org.testcontainers.utility.MountableFile.lambda$deleteOnExit$0(MountableFile.java:318)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassNotFoundException: org.testcontainers.utility.PathUtils
	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)
	... 2 more
	

avasenin avatar Dec 11 '23 17:12 avasenin

https://github.com/testcontainers/testcontainers-java/issues/1454 this issue is not solved. it should be reopened.

(and it reopened. good.)

SightStudio avatar Feb 01 '24 05:02 SightStudio

Does it even work? https://github.com/testcontainers/testcontainers-java/issues/1454#issuecomment-518707266

Hmm, I'm not really sure if we can help much with this. Running Testcontainers code directly from a Maven plugin isn't something we've attempted to support, as we're more focused on testing. I assume your usage scenarios are not testing?

As you say it does look like the Maven classloader closing is what's causing it. If that's Maven's classloader behaviour then I imagine shutdown hooks are essentially not safe inside of a Maven plugin, and should be avoided.

If there's something simple that we could change then I think we could accept a PR, but otherwise I'm afraid we might have to chalk this up as an unsupported use case. Sorry to disappoint.

Looks like this plugin is not supported by the authors from the same organization... do I not understand something?

oxygenecore avatar Mar 06 '24 10:03 oxygenecore

(this relates both to testcontainers-java and to this maven plugin, so posting here as well)

This is what Maven documentation states: https://maven.apache.org/plugin-developers/common-bugs.html#using-shutdown-hooks

The problem is that the JVM executing Maven can be running much longer than the actual Maven build. Of course, this does not apply to the standalone invocation of Maven from the command line. However, it affects the embedded usage of Maven in IDEs or CI servers. In those cases, the cleanup tasks will be deferred, too. If the JVM is then executing a bunch of other Maven builds, many such cleanup tasks can sum up, eating up resources of the JVM.

For this reason, plugin developers should avoid usage of shutdown hooks and rather use try/finally blocks to perform cleanup as soon as the resources are no longer needed.

So, I guess, the maven plugin should clean up the shutdown hooks created by testcontainers-java? Or rather - remove them from the shutdown hooks and execute them in finally block?

oxygenecore avatar Mar 06 '24 11:03 oxygenecore

Any news here?

I get the same error with MYSQL, followed the official guide: testcontainers-jooq-codegen-maven-plugin-guide

Exception in thread "Thread-5" java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils at org.testcontainers.utility.MountableFile.lambda$deleteOnExit$0(MountableFile.java:318) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: java.lang.ClassNotFoundException: org.testcontainers.utility.PathUtils 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) ... 2 more

MixFr avatar Mar 19 '24 14:03 MixFr

@oxygenecore The comment you quoted from https://github.com/testcontainers/testcontainers-java/issues/1454 is from 2019, it significantly predates the creation of this plugin and hence is not related with regards to org not supporting this plugin. However, the technical investigation is of course related.

@sivaprasadreddy is the author of this plugin. I don't know if this exception (maybe originating from executing of the shutdown hook) is really an issue in the context of this use case (which file are we supposed to delete?). Can we technically remove the shutdown hook from within the plugin?

kiview avatar Apr 25 '24 10:04 kiview

@kiview This is a known issue due to the mentioned testcontainers-java issue#1454. Even though it logs the error, it generates the JOOQ code. How to actually fix the shutdown hook problem is yet to be explored.

sivaprasadreddy avatar May 28 '24 02:05 sivaprasadreddy

Even though it logs the error, it generates the JOOQ code.

In this case, I'd consider this issue very low severity and fixing it is more of a nice to have.

kiview avatar May 28 '24 15:05 kiview

Even though it logs the error, it generates the JOOQ code.

In this case, I'd consider this issue very low severity and fixing it is more of a nice to have.

I also think, that the issue is low severity, but it shouldn’t be ignored, since it looks terrible to see always the stacktrace in each build.

Also for new users it isn’t a good experience.

MixFr avatar May 28 '24 15:05 MixFr

In this case, I'd consider this issue very low severity and fixing it is more of a nice to have.

This might be a low level of severity. but I had to show this issue whenever user around me asked about this.

So until this issue is resolved, it should be pinned or specified in README, or at least mentioned on below page.

https://testcontainers.com/guides/working-with-jooq-flyway-using-testcontainers/

but I'm glad this issue goes active. 😃

SightStudio avatar May 28 '24 15:05 SightStudio

Please note that this only happens with MariaDB: https://github.com/testcontainers/testcontainers-java/issues/1454#issuecomment-1018508784

Sure it's annoying but it's not a bug of the plugin so IMO this issue should be closed.

simasch avatar May 28 '24 15:05 simasch

Please note that this only happens with MariaDB: testcontainers/testcontainers-java#1454 (comment)

Sure it's annoying but it's not a bug of the plugin so IMO this issue should be closed.

We are using MYSQL and we see the same error. So it is not only related to MariaDB.

MixFr avatar May 28 '24 16:05 MixFr

Ok let's say it's MySQL/MariaDB problem. BUT again it's not a bug of the plugin.

simasch avatar May 28 '24 16:05 simasch

Ok let's say it's MySQL/MariaDB problem. BUT again it's not a bug of the plugin.

How should the issue then be dealt with?

MixFr avatar May 28 '24 19:05 MixFr

It's covered by this issue https://github.com/testcontainers/testcontainers-java/issues/1454

simasch avatar May 28 '24 19:05 simasch