mobie / mobie-viewer-fiji

BSD 2-Clause "Simplified" License
29 stars 12 forks source link

Legacy Injector not working #1139

Closed tischi closed 1 month ago

tischi commented 1 month ago

Dear @ctrueden,

We are having again the Legacy Injector issue in the current main branch, when running mvn test.

Caused by: java.lang.RuntimeException: Found incompatible ImageJ class
        at net.imagej.patcher.LegacyEnvironment.initialize(LegacyEnvironment.java:112)
        at net.imagej.patcher.LegacyEnvironment.applyPatches(LegacyEnvironment.java:494)
        at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:400)
        at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:379)
        at org.embl.mobie.lib.hcs.HCSPatternTest.<clinit>(HCSPatternTest.java:37)
        ... 71 more
Caused by: java.lang.RuntimeException: Cannot load class: ij.ImagePlus (loader: sun.misc.Launcher$AppClassLoader@18b4aac2)
It appears that this class was already defined in the class loader!
Please make sure that you initialize the LegacyService before using
any ImageJ 1.x class. You can do that by adding this static initializer:

        static {
                LegacyInjector.preinit();
        }

Could you please do your magic again for fixing this? Which I think was adding static { net.imagej.patcher.LegacyInjector.preinit(); } to all classes?! If you tell me how to do this I can also do it myself...

Thanks!

tischi commented 1 month ago

@K-Meech do you also have the above issue? Sometimes this sort of issues are different on different computers....

ctrueden commented 1 month ago

I believe the commit that broke things is 2bdd137dd9c13f64f3f33c493d9258c4a89b442b, which changed some methods to have ij.ImagePlus as a return type or parameter, thus causing ImageJ to be loaded too early. If you rm src/test/java/org/embl/mobie/lib/create/ImagesCreatorTest.java and then mvn clean test then the test suite passes. I theorize that the preinit static initializer trick does not help in that class because it's already recursively loaded ImageJ by the time the static initializer block is called.

I filed PR #1141 to address it.