Skip to content

Commit 4d08a9f

Browse files
jeet1995Copilot
andcommitted
Fix forked JVM test for Java 8 compatibility
--add-opens is only available on JDK 9+. Parse java.specification.version (returns '1.8' on JDK 8, '11'/'17'/'21' on newer) and only add the flag when major version >= 9. Works on JDK 8+ (where '1.8'.split('.')[0] = '1' which is < 9). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 06a4f83 commit 4d08a9f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/implementation/ImplementationBridgeHelpersTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,18 @@ public void concurrentAccessorInitializationShouldNotDeadlock() throws Exception
128128

129129
List<String> command = new ArrayList<>();
130130
command.add(javaBin);
131-
command.add("--add-opens");
132-
command.add("java.base/java.lang=ALL-UNNAMED");
131+
132+
// --add-opens is only supported on JDK 9+
133+
try {
134+
int majorVersion = Integer.parseInt(System.getProperty("java.specification.version").split("\\.")[0]);
135+
if (majorVersion >= 9) {
136+
command.add("--add-opens");
137+
command.add("java.base/java.lang=ALL-UNNAMED");
138+
}
139+
} catch (NumberFormatException e) {
140+
// JDK 8 returns "1.8" — first element is "1", which is < 9, so no --add-opens
141+
}
142+
133143
command.add("-cp");
134144
command.add(classpath);
135145
command.add(ConcurrentClinitChildProcess.class.getName());

0 commit comments

Comments
 (0)