Skip to content

Commit

Permalink
Recognize Java 9.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pmwmedia committed Nov 14, 2017
1 parent 24a205f commit d2acda3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion tinylog-core/src/org/pmw/tinylog/EnvironmentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ private EnvironmentHelper() {
*/
public static boolean isAtLeastJava9() {
String version = System.getProperty("java.version");
return version != null && version.matches("[0-9]{1,8}") && Integer.parseInt(version) >= 9;
if (version == null) {
return false;
} else {
int index = version.indexOf('.');
if (index > 0) {
version = version.substring(0, index);
}
return version.matches("[0-9]{1,8}") && Integer.parseInt(version) >= 9;
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion tinylog-core/test/org/pmw/tinylog/EnvironmentHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public final void testDetectingJava9OrHigher() {
System.setProperty("java.version", "9");
assertTrue(EnvironmentHelper.isAtLeastJava9());

System.setProperty("java.version", "9.0.1");
assertTrue(EnvironmentHelper.isAtLeastJava9());

System.setProperty("java.version", "10");
assertTrue(EnvironmentHelper.isAtLeastJava9());
} finally {
Expand Down Expand Up @@ -217,7 +220,6 @@ public final void testReceivingLegacyJavaDialect() {
}
}


/**
* Test receiving {@class ModernJavaRuntime} as runtime dialect on Java 9 or higher.
*/
Expand All @@ -228,6 +230,9 @@ public final void testReceivingModernJavaDialect() {
System.setProperty("java.version", "9");
assertThat(Deencapsulation.invoke(EnvironmentHelper.class, "resolveDialect"), instanceOf(ModernJavaRuntime.class));

System.setProperty("java.version", "9.0.1");
assertThat(Deencapsulation.invoke(EnvironmentHelper.class, "resolveDialect"), instanceOf(ModernJavaRuntime.class));

System.setProperty("java.version", "10");
assertThat(Deencapsulation.invoke(EnvironmentHelper.class, "resolveDialect"), instanceOf(ModernJavaRuntime.class));
} finally {
Expand Down

0 comments on commit d2acda3

Please sign in to comment.