Skip to content

Add --add-opens java.base/sun.nio.ch=ALL-UNNAMED - #3143

Open
jbonofre wants to merge 1 commit into
apache:mainfrom
jbonofre:add-opens-sun-nio-ch
Open

jbonofre wants to merge 1 commit into
apache:mainfrom
jbonofre:add-opens-sun-nio-ch

Conversation

@jbonofre

Copy link
Copy Markdown
Member

Fixes #2299.

Context

Code that reflects on sun.nio.ch internals, for example to tune NIO sockets or selectors, fails with InaccessibleObjectException on JDK 17+ unless the package is opened. Users can add the flag through EXTRA_JAVA_OPTS in bin/setenv, but that only reaches bin/karaf. It doesn't reach the service wrapper or child instances started with instance:start.

#2300 (by @mattrpav) was closed as already covered by the JDK 21 lift (#2214), but #2214 doesn't contain the flag and neither main nor karaf-4.4.x has it. #2840 (by @Alwaysgaurav1) covered every launch path but was closed as a duplicate of #2300, and it no longer applies after #2214. This PR picks the change up again on current main. Thanks to both.

Changes

--add-opens java.base/sun.nio.ch=ALL-UNNAMED is added next to the other java.base opens in:

  • bin/karaf and bin/karaf.bat (instance scripts exec the root bin/karaf)
  • InstanceServiceImpl, for child instances started by instance:start
  • the unix, windows and windows64 karaf-wrapper-java11.conf
  • the Pax Exam options in KarafTestSupport and KarafMinimalMonitoredTestSupport

Testing

JDK 21, apache-karaf distribution built from this branch. The probe, run from the console, is (($.context bundle 0) loadClass "sun.nio.ch.SelectorImpl") getDeclaredField "selectedKeys" followed by trySetAccessible:

Launch path Flag on the JVM trySetAccessible
bin/karaf without the flag (control) no false
bin/start yes true
instance:create + instance:start yes true
wrapper:install: generated etc/karaf-wrapper.conf JDK_JAVA_OPTIONS value yes true

The bundled macOS wrapper binary is a PowerPC Mach-O and doesn't run on current Macs. For the wrapper row, Karaf was started with the generated JDK_JAVA_OPTIONS value in the environment, which is how the wrapper passes it.

  • mvn test -pl instance: 36 tests, 0 failures.
  • itests/test, -Dtest=InstanceTest,SystemTest,MavenResolverRegisteredBeforeConfigAdminTest,MavenResolverRegisteredOnlyAfterConfigAdminTest: 18 tests, 0 failures. ps on a running Pax Exam container shows the new option.

Code that reflects on sun.nio.ch internals, for example to tune NIO
sockets or selectors, fails with InaccessibleObjectException on JDK 17+
unless the package is opened to the unnamed module.

Add the flag next to the other java.base opens on every launch path:
- bin/karaf and bin/karaf.bat
- child instances started by instance:start (InstanceServiceImpl)
- service wrapper configurations (unix, windows, windows64)
- Pax Exam options in KarafTestSupport and KarafMinimalMonitoredTestSupport

Fixes apache#2299
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Test Results

1 112 files  ±0  1 112 suites  ±0   1h 13m 45s ⏱️ - 17m 18s
1 367 tests ±0  1 235 ✅  - 1  131 💤 ±0  1 ❌ +1 
5 468 runs  ±0  4 941 ✅  - 1  526 💤 ±0  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 3fc4767. ± Comparison against base commit e74d795.

♻️ This comment has been updated with latest results.

@jbonofre

Copy link
Copy Markdown
Member Author

It needs the #3145 fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --add-opens java.base/sun.nio.ch=ALL-UNNAMED

1 participant