diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/JavaVersionUtils.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/JavaVersionUtils.java index 7fa7407849..7f5ec3dc02 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/JavaVersionUtils.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/JavaVersionUtils.java @@ -13,11 +13,10 @@ * Simple set of utilities to help us validate that the agent is being run on a supported version of Java. */ public class JavaVersionUtils { - private static final Pattern SUPPORTED_JAVA_VERSION_PATTERN = Pattern.compile("^(1\\.7|1\\.8|9|1[0-5])$"); - private static final Pattern EXCLUSIVE_MIN_JAVA_VERSION_PATTERN = Pattern.compile("^1\\.6$"); + private static final Pattern SUPPORTED_JAVA_VERSION_PATTERN = Pattern.compile("^(1\\.8|9|1[0-5])$"); + private static final Pattern EXCLUSIVE_MIN_JAVA_VERSION_PATTERN = Pattern.compile("^1\\.7$"); private static final Pattern EXCLUSIVE_MAX_JAVA_VERSION_PATTERN = Pattern.compile("^16$"); - public static final String JAVA_6 = "1.6"; public static final String JAVA_7 = "1.7"; public static final String JAVA_8 = "1.8"; public static final String JAVA_9 = "9"; @@ -50,8 +49,8 @@ public static String getUnsupportedAgentJavaSpecVersionMessage(String javaSpecif StringBuilder message = new StringBuilder(); if (EXCLUSIVE_MIN_JAVA_VERSION_PATTERN.matcher(javaSpecificationVersion).matches()) { message.append("Java version is: ").append(javaSpecificationVersion).append(". "); - message.append("This version of the New Relic Agent does not support Java 1.6 or below. ") - .append("Please use a 4.3.x New Relic agent or a later version of Java."); + message.append("This version of the New Relic Agent does not support Java 1.7 or below. ") + .append("Please use a 6.5.0 New Relic agent or a later version of Java."); } else if (EXCLUSIVE_MAX_JAVA_VERSION_PATTERN.matcher(javaSpecificationVersion).matches()) { message.append("Java version is: ").append(javaSpecificationVersion).append(". "); message.append("This version of the New Relic Agent does not support versions of Java greater than 15."); diff --git a/newrelic-agent/src/test/java/com/newrelic/agent/config/JavaVersionUtilsTest.java b/newrelic-agent/src/test/java/com/newrelic/agent/config/JavaVersionUtilsTest.java index be052ec016..73eca92d72 100644 --- a/newrelic-agent/src/test/java/com/newrelic/agent/config/JavaVersionUtilsTest.java +++ b/newrelic-agent/src/test/java/com/newrelic/agent/config/JavaVersionUtilsTest.java @@ -10,6 +10,7 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.containsString; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -18,7 +19,6 @@ public class JavaVersionUtilsTest { @Test public void supportAgentJavaSpecVersions() { - assertTrue(JavaVersionUtils.isAgentSupportedJavaSpecVersion(JavaVersionUtils.JAVA_7)); assertTrue(JavaVersionUtils.isAgentSupportedJavaSpecVersion(JavaVersionUtils.JAVA_8)); assertTrue(JavaVersionUtils.isAgentSupportedJavaSpecVersion(JavaVersionUtils.JAVA_9)); assertTrue(JavaVersionUtils.isAgentSupportedJavaSpecVersion(JavaVersionUtils.JAVA_10)); @@ -30,7 +30,7 @@ public void supportAgentJavaSpecVersions() { } @Test - public void unsupportedAgentVersionsLessThanJava7() { + public void unsupportedAgentVersionsLessThanJava8() { assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.5")); assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.5.0")); assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.5.0_11")); @@ -41,10 +41,15 @@ public void unsupportedAgentVersionsLessThanJava7() { assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.6.0_11")); assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.6.0_11-b12")); assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.6.1_gibberish")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.7")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.7.0")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.7.0_11")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.7.0_11-b12")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("1.7.1_gibberish")); } @Test - public void unsupportedAgentVersionsExceedingJava14() { + public void unsupportedAgentVersionsExceedingJava15() { assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("16.0")); assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("16+181")); assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("16.0+181")); @@ -71,10 +76,10 @@ public void otherUnsupportedVersionStrings() { } @Test - public void unsupportedJavaVersionMessageWhenLessThanJava7() { - String msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(JavaVersionUtils.JAVA_6); - assertThat(msg, containsString(JavaVersionUtils.JAVA_6)); - assertThat(msg, containsString("4.3.x New Relic agent")); + public void unsupportedJavaVersionMessageWhenLessThanJava8() { + String msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(JavaVersionUtils.JAVA_7); + assertThat(msg, containsString(JavaVersionUtils.JAVA_7)); + assertThat(msg, containsString("6.5.0 New Relic agent")); } @Test @@ -87,10 +92,10 @@ public void unsupportedJavaVersionMessageWhenGreaterThanJava9() { @Test public void emptyMessageReturnedWhenJavaVersionSupported() { String msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(JavaVersionUtils.JAVA_8); - assertTrue(msg.length() == 0); + assertEquals(0, msg.length()); msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(null); - assertTrue(msg.length() == 0); + assertEquals(0, msg.length()); } }