This is an automated email from the ASF dual-hosted git repository.
olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/master by this push:
new 97089cdc9 [SUREFIRE-1735] Don't NPE on a release file without
JAVA_VERSION (#3602)
97089cdc9 is described below
commit 97089cdc912022b3fccf49395f4a9cdc804f8a9d
Author: Arturo Bernal <[email protected]>
AuthorDate: Tue Nov 17 03:43:45 2026 +0100
[SUREFIRE-1735] Don't NPE on a release file without JAVA_VERSION (#3602)
SystemUtils.toJdkVersionFromReleaseFile() read a JDK's release file and
called .replace() on properties.getProperty("JAVA_VERSION") without
checking for null. Some JDK distributions, including certain GraalVM
builds, ship a release file that has no JAVA_VERSION entry, so using
such a JDK as a <toolchain> (with a different default JAVA_HOME) threw
an NPE instead of surfacing a usable error.
Every other detection failure in this method (missing release file,
unreadable file) already falls back to returning null so the caller
treats the JDK version as unknown; this now does the same for a
present-but-incomplete release file.
Claude-Session: https://claude.ai/code/session_01BrsHTdDq7PD1DoqeA9vs66
---
.../java/org/apache/maven/surefire/booter/SystemUtils.java | 7 ++++++-
.../org/apache/maven/surefire/booter/SystemUtilsTest.java | 11 +++++++++++
.../src/test/resources/graalvm-no-java-version/release | 2 ++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git
a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java
b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java
index 3600bffb6..aa7435d53 100644
---
a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java
+++
b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SystemUtils.java
@@ -132,7 +132,12 @@ public static BigDecimal toJdkVersionFromReleaseFile(File
jdkHome) {
Properties properties = new Properties();
try (InputStream is = new FileInputStream(release)) {
properties.load(is);
- String javaVersion =
properties.getProperty("JAVA_VERSION").replace("\"", "");
+ String javaVersion = properties.getProperty("JAVA_VERSION");
+ if (javaVersion == null) {
+ // some JDK distributions (e.g. certain GraalVM builds) ship a
release file without this key
+ return null;
+ }
+ javaVersion = javaVersion.replace("\"", "");
StringTokenizer versions = new StringTokenizer(javaVersion, "._");
if (versions.countTokens() == 1) {
diff --git
a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java
b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java
index c3e04dd36..0c9af2a1e 100644
---
a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java
+++
b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/SystemUtilsTest.java
@@ -74,6 +74,17 @@ public void shouldParseProprietaryReleaseFile() throws
IOException {
assertThat(SystemUtils.isJava9AtLeast(path.getAbsolutePath())).isTrue();
}
+ @Test
+ public void shouldNotThrowOnReleaseFileWithoutJavaVersion() throws
IOException {
+ String classes = new File(".").getCanonicalPath() + separator +
"target" + separator + "test-classes";
+
+ File path = new File(classes, "graalvm-no-java-version" +
separator + "bin" + separator + "java");
+
assertThat(SystemUtils.isJava9AtLeast(path.getAbsolutePath())).isFalse();
+
+ File jdkHome = new File(classes, "graalvm-no-java-version");
+
assertThat(SystemUtils.toJdkVersionFromReleaseFile(jdkHome)).isNull();
+ }
+
@Test
public void shouldHaveJavaPath() {
String javaPath = System.getProperty("java.home") + separator +
"bin" + separator + "java";
diff --git a/surefire-booter/src/test/resources/graalvm-no-java-version/release
b/surefire-booter/src/test/resources/graalvm-no-java-version/release
new file mode 100644
index 000000000..7441e91f0
--- /dev/null
+++ b/surefire-booter/src/test/resources/graalvm-no-java-version/release
@@ -0,0 +1,2 @@
+IMPLEMENTOR="GraalVM Community"
+OS_NAME="Linux"