Skip to content

Commit

Permalink
[SUREFIRE-1939] Fix NPE in SystemUtils.toJdkHomeFromJvmExec if java h…
Browse files Browse the repository at this point in the history
…ome has 2 components
  • Loading branch information
CMoH committed Nov 13, 2021
1 parent 670dbe4 commit a6bc580
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit a6bc580

Please sign in to comment.