Skip to content

[4.4.x] Add --add-opens java.base/sun.nio.ch=ALL-UNNAMED - #3144

Merged
jbonofre merged 1 commit into
apache:karaf-4.4.xfrom
jbonofre:backport-3143-karaf-4.4.x
Nov 21, 2026
Merged

jbonofre merged 1 commit into
apache:karaf-4.4.xfrom
jbonofre:backport-3143-karaf-4.4.x

Conversation

@jbonofre

@jbonofre jbonofre commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Backport of #3143 to karaf-4.4.x. Fixes #2299 on 4.4.x.

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. karaf-4.4.x doesn't open it on any launch path either. On JDK 11 the default --illegal-access=permit still allows it with a warning, so the change matters for 4.4.x users on JDK 17 and 21.

Changes

Same as #3143. --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 (in the JDK 9+ branch)
  • 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

The cherry-pick conflicted only on context lines, because 4.4.x has the --add-reads/--patch-module options and no --enable-native-access. The flag was re-applied at the same place in each list, and bin/karaf.bat keeps its CRLF line endings.

Testing

apache-karaf 4.4.13-SNAPSHOT distribution built from this branch (full reactor, compiled for Java 11). The probe, run from the console, is (($.context bundle 0) loadClass "sun.nio.ch.SelectorImpl") getDeclaredField "selectedKeys" followed by trySetAccessible:

JDK Launch path Flag on the JVM trySetAccessible
17 bin/karaf without the flag (control) no false
17 bin/start yes true
17 instance:create + instance:start yes true
17 wrapper:install: generated etc/karaf-wrapper.conf yes (JDK_JAVA_OPTIONS) not run, see below
11 bin/karaf without the flag (control) no true, plus an Illegal reflective access ... to field sun.nio.ch.SelectorImpl.selectedKeys warning
11 bin/start yes true, no warning

The bundled macOS wrapper binary is a PowerPC Mach-O, so the wrapper itself can't run on a current Mac. On main (#3143), starting Karaf with the generated JDK_JAVA_OPTIONS value gave true. That emulation doesn't work on 4.4.x, because the value repeats the --patch-module options bin/karaf already passes.

  • JDK 11, mvn test -pl instance: 32 tests, 0 failures.
  • JDK 11, itests/test, -Dtest=InstanceTest,SystemTest,MavenResolverRegisteredBeforeConfigAdminTest,MavenResolverRegisteredOnlyAfterConfigAdminTest: 18 tests, 0 failures, 2 skipped (the two MavenResolver tests are @Ignored on 4.4.x). 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

Backport of apache#3143.
@github-actions

Copy link
Copy Markdown

Test Results

  694 files  ±0    694 suites  ±0   58m 11s ⏱️ -36s
1 084 tests ±0  1 041 ✅ ±0   43 💤 ±0  0 ❌ ±0 
2 977 runs  ±0  2 856 ✅ ±0  121 💤 ±0  0 ❌ ±0 

Results for commit 6b6b890. ± Comparison against base commit 99ec5dc.

@jbonofre
jbonofre merged commit 199507a into apache:karaf-4.4.x Nov 21, 2026
7 checks passed
@jbonofre
jbonofre deleted the backport-3143-karaf-4.4.x branch November 21, 2026 13:44
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.

1 participant