Skip to content

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

Merged
jbonofre merged 1 commit into
apache:mainfrom
jbonofre:add-opens-sun-nio-ch
Nov 22, 2026
Merged

jbonofre merged 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.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Test Results

1 112 files  ±0  1 112 suites  ±0   1h 21m 12s ⏱️ + 1m 35s
1 367 tests ±0  1 236 ✅ ±0  131 💤 ±0  0 ❌ ±0 
5 468 runs  ±0  4 942 ✅ ±0  526 💤 ±0  0 ❌ ±0 

Results for commit 765418e. ± Comparison against base commit e568396.

♻️ This comment has been updated with latest results.

@jbonofre

Copy link
Copy Markdown
Member Author

It needs the #3145 fix.

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
@jbonofre
jbonofre force-pushed the add-opens-sun-nio-ch branch from 3fc4767 to 765418e Compare November 22, 2026 04:34
@jbonofre
jbonofre merged commit cd071d6 into apache:main Nov 22, 2026
9 checks passed
@jbonofre
jbonofre deleted the add-opens-sun-nio-ch branch November 22, 2026 05:25
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