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 ab7538a7c2..8f47478fc5 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 @@ -88,7 +88,7 @@ public static boolean endsWithJavaPath( String jvmExecPath ) public static File toJdkHomeFromJvmExec( String jvmExecutable ) { File bin = new File( jvmExecutable ).getAbsoluteFile().getParentFile(); - if ( "bin".equals( bin.getName() ) ) + if ( bin != null && "bin".equals( bin.getName() ) ) { File parent = bin.getParentFile(); if ( "jre".equals( parent.getName() ) ) 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 c504e04d9d..f36ece51d4 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 @@ -98,6 +98,15 @@ public void incorrectJdkPath() assertThat( SystemUtils.isJava9AtLeast( incorrect.getAbsolutePath() ) ).isFalse(); } + @Test + public void incorrectJdkPathShouldNotNPE() + { + File jre = new File( "/opt/jdk" ); + File jdk = jre.getParentFile(); + File incorrect = jdk.getParentFile(); + assertThat( SystemUtils.isJava9AtLeast( incorrect.getAbsolutePath() ) ).isFalse(); + } + @Test public void shouldHaveJavaPath() {