xazap commented on PR #897: URL: https://github.com/apache/commons-io/pull/897#issuecomment-7020499800
Ok, back to the original problem: Instantiating `sun.misc.Unsafe` gives `ClassNotFoundException` in Java 9+ with commons-io placed on the module path. I previously incorrectly assumed that Java 9+ did not have `sun.misc.Unsafe` anymore. It does still provide this class at least up to Java 25 as far as I can tell. The `ClassNotFoundException` is thrown because the (Moditect) generated module-info only requires the `java.base` module whereas `sun.misc.Unsafe` resides in the `jdk.unsupported` module. The Moditect plugin in the commons-parent POM is setup to include required modules automatically, but it doesn't do so for module `jdk.unsupported` because it cannot find a static reference to `sun.misc.Unsafe` because we are loading it with `Class::forName`. I therefore changed the project's moditect-plugin configuration to generate a module-info with `requires jdk.unsupported`. Unfortunately I had to duplicate the plugin's parent configuration. It would have been preferable to add a requires entry to the inherited plugin configuration. I did try this but found out it doesn't work: if Moditect doesn't see a static reference to anything in a module it would not output the requires line in module-info. So I ended up putting a static module-info in the POM. As for the unit tests on the module path, my earlier comments and the CodePilot review show that it's not done correctly. I therefore reverted back to classpath unit tests only. I think unit tests on the module path can only be done correctly by executing the unit tests on the module path AFTER the JAR has been packaged so that the module-info descriptor is available. This is a lot of work and does not fit in neatly with the parent POM. I think this is best done once commons-io drops the Java 8 requirement. With this I believe the original problem described in IO-895 is now fixed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
