Skip to content

Commit

Permalink
More polish to java version parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlauer committed Nov 3, 2023
1 parent cbbc601 commit 767990a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/fizzed/jne/JavaHomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ static public List<JavaHome> detect() throws Exception {
try {
javaHome = JavaHomes.fromDirectory(maybeJavaHome);
javaHomes.add(javaHome);
} catch (FileNotFoundException e) {
} catch (Exception e) {
// not a jvm
log.info(" was NOT a java home");
log.info(" was NOT a java home", e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fizzed/jne/JavaVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static public JavaVersion parse(String version) {
// pre-Java 9 version number
if (version.startsWith("1.")) {
// e.g. 1.8.0_352 which we normalize to the modern format so we can use its parsing routing
sourceVersion = version.substring(2).replace('_', '.');
sourceVersion = version.substring(2).replace('_', '.').replace('-', '.');
}

final int len = sourceVersion.length();
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/com/fizzed/jne/JavaVersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ public void legacyVersion() {
assertThat(v.getBuild(), is(0));
assertThat(v.toString(), is("7.0.45"));
assertThat(v.toJavaVersion(), is("1.7.0_45"));

v = JavaVersion.parse("1.6.0-119");
assertThat(v.getMajor(), is(6));
assertThat(v.getMinor(), is(0));
assertThat(v.getSecurity(), is(119));
assertThat(v.getBuild(), is(0));
assertThat(v.toString(), is("6.0.119"));
assertThat(v.toJavaVersion(), is("1.6.0_119"));
}

}

0 comments on commit 767990a

Please sign in to comment.