testcontainers / testcontainers-jooq-codegen-maven-plugin

jOOQ code generator using Testcontainers
Apache License 2.0
48 stars 10 forks source link

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

Open avasenin opened 7 months ago

avasenin commented 7 months ago

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
SightStudio commented 5 months ago

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

(and it reopened. good.)

oxygenecore commented 4 months ago

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 commented 4 months ago

(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?

MixFr commented 4 months ago

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

kiview commented 3 months ago

@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?

sivaprasadreddy commented 2 months ago

@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.

kiview commented 2 months ago

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.

MixFr commented 2 months ago

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.

SightStudio commented 2 months ago

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. 😃

simasch commented 2 months ago

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.

MixFr commented 2 months ago

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.

simasch commented 2 months ago

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

MixFr commented 2 months ago

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?

simasch commented 2 months ago

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