Skip to content
Permalink
Browse files
Revert "Throw unsupported exception when using Java 9 or 10 runtime"
This reverts commit 52263c8.
  • Loading branch information
davecromberge committed May 10, 2022
1 parent 52263c8 commit 7bc861c9b4c705e845c6d483037035b272a82af9
Showing 2 changed files with 43 additions and 25 deletions.
@@ -43,7 +43,7 @@ public class UnsafeUtilTest {
public void checkJdkString() {
String jdkVer;
int[] p = new int[2];
String[] good1_Strings = {"1.8.0_121", "8", "11", "12", "13"};
String[] good1_Strings = {"1.8.0_121", "8", "9", "10", "11", "12", "13"};
int len = good1_Strings.length;
for (int i = 0; i < len; i++) {
jdkVer = good1_Strings[i];
@@ -53,14 +53,47 @@ public void checkJdkString() {
if (p[0] == 1) { assertTrue(jdkMajor == p[1]); }
if (p[0] > 1 ) { assertTrue(jdkMajor == p[0]); }
}
try {
jdkVer = "14.0.4"; //ver 14 string
p = UnsafeUtil.parseJavaVersion(jdkVer);
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]);
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}

invalidVersionTest("14.0.4"); // ver 14 string
invalidVersionTest("1.7.0_80"); // ver 1.7 string
invalidVersionTest("9.0.4_80"); // ver 9 string
invalidVersionTest("10.0.2_80"); // ver 10 string
invalidVersionTest("1.6.0_65"); // ver < 1.8 string
invalidVersionTest("b"); // invalid version
invalidVersionTest(""); // invalid version
try {
jdkVer = "1.7.0_80"; //1.7 string
p = UnsafeUtil.parseJavaVersion(jdkVer);
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]);
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
jdkVer = "1.6.0_65"; //valid string but < 1.7
p = UnsafeUtil.parseJavaVersion(jdkVer);
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
jdkVer = "b"; //invalid string
p = UnsafeUtil.parseJavaVersion(jdkVer);
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
try {
jdkVer = ""; //invalid string
p = UnsafeUtil.parseJavaVersion(jdkVer);
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); //throws
fail();
} catch (IllegalArgumentException e) {
println("" + e);
}
}

@Test
@@ -118,19 +151,4 @@ static void println(final String s) {
//System.out.println(s);
}

/**
* @param jdkVer java runtime version identifier
*/
static void invalidVersionTest(final String jdkVer)
{
try {
int[] p = new int[2];
p = UnsafeUtil.parseJavaVersion(jdkVer);
UnsafeUtil.checkJavaVersion(jdkVer, p[0], p[1]); //throws
fail();
}
catch (IllegalArgumentException e) {
println("" + e);
}
}
}
@@ -144,9 +144,9 @@ public static int[] parseJavaVersion(final String jdkVer) {
}

public static void checkJavaVersion(final String jdkVer, final int p0, final int p1) {
if ( (p0 < 1) || ((p0 == 1) && (p1 < 8)) || (p0 == 9) || (p0 == 10) || (p0 > 13) ) {
if ( (p0 < 1) || ((p0 == 1) && (p1 < 8)) || (p0 > 13) ) {
throw new IllegalArgumentException(
"Unsupported JDK Major Version, must be one of 1.8, 8, 11, 12, 13: " + jdkVer);
"Unsupported JDK Major Version, must be one of 1.8, 8, 9, 10, 11, 12, 13: " + jdkVer);
}
}

0 comments on commit 7bc861c

Please sign in to comment.