Repository navigation
Conversation
agammann
left a comment
There was a problem hiding this comment.
The Java 9+ path now invokes sun.nio.ch.DirectBuffer.cleaner() and jdk.internal.ref.Cleaner.clean() reflectively. Both packages need the --add-opens flags added to the Maven test profile, so those tests do not exercise a normal classpath consumer with no extra JVM arguments. In that case, wouldn’t clean(..., true) fail with IllegalAccessException at invocation? The previous Java9Cleaner used Unsafe.invokeCleaner for that case. Could you retain a no-flags path and add a subprocess test without --add-opens? This would check that the module-path fix does not regress the default classpath use.
… in stacktrace to Java 9+ failure
|
It turns out my previous assessment of needing an alternative the sun.misc.Unsafe was because of the misleading stacktrace. I reverted the The assumed The POM was changed to make the unit tests do two passes on Java 9+: one with classes on the classpath and another one on the module path. Not sure if POM changes should be kept: when testing on the module path it needs some Anyway, I pushed my latest insights to the PR. The stacktrace fix is worth merging I think as that provides the hints on what |
|
Thanks for investigating and reverting the reflective cleaner change; that addresses the no-flags regression I raised. One POM detail to check on head |
There was a problem hiding this comment.
🟡 Changes recommended
The cleaner still fails initialization when jdk.unsupported is unresolved, while the Maven test configuration neither updates the normal test execution nor exercises the intended named-module scenario.
3 open issues
What changed in this PR
This PR targets IO-895, a Commons IO buffer-cleaner initialization failure on the Java module path, with improved exception reporting and revised test configuration.
Changes:
- Reports the Java 9+ cleaner initialization exception as the failure cause.
- Extracts shared Surefire JVM arguments into a reusable property.
- Adds Java 9+ test configuration intended to separate classpath and module-path runs.
| File | Description |
|---|---|
| src/main/java/org/apache/commons/io/input/ByteBufferCleaner.java | Corrects the cause reported when cleaner initialization fails. |
| pom.xml | Reuses Surefire JVM arguments and adds intended classpath/module-path test configurations. |
Review effort: Balanced
| return new Java9Cleaner(); | ||
| } catch (final Exception e1) { | ||
| throw new IllegalStateException("Failed to initialize a direct ByteBuffer Cleaner.", e); | ||
| throw new IllegalStateException("Failed to initialize a direct ByteBuffer Cleaner.", e1); |
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <id>default-test-on-classpath</id> |
| <goal>test</goal> | ||
| </goals> | ||
| <configuration> | ||
| <useModulePath>true</useModulePath> |
…misc.Unsafe can be used on the module path
|
Ok, back to the original problem: Instantiating I therefore changed the project's moditect-plugin configuration to generate a module-info with 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. |
…ing-Commons-IO-on-the-module-path
|
I packaged I used both JARs to read and close the same file with The smoke test covered one stream path on two JDKs. The full test suite was outside this run. The draft description still mentions |


This PR seeks to fix the bug described in IO-895.
Changes made in org.apache.commons.io.input.ByteBufferCleaner
should an ExceptionInInitializerError occur, it now provides the correct root cause whereas the previous implementation always provided the stacktrace of the Java 8 failure.
Testing
Runtime considerations when using Commons IO on the module path
What could be better:
Why this should be merged: