aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/pom.xml2
-rw-r--r--util/src/main/java/org/aspectj/util/LangUtil.java25
2 files changed, 16 insertions, 11 deletions
diff --git a/util/pom.xml b/util/pom.xml
index ca3e31e75..0866d18e3 100644
--- a/util/pom.xml
+++ b/util/pom.xml
@@ -6,7 +6,7 @@
<parent>
<groupId>org.aspectj</groupId>
<artifactId>aspectj-parent</artifactId>
- <version>1.9.10-SNAPSHOT</version>
+ <version>1.9.19-SNAPSHOT</version>
</parent>
<artifactId>util</artifactId>
diff --git a/util/src/main/java/org/aspectj/util/LangUtil.java b/util/src/main/java/org/aspectj/util/LangUtil.java
index d916002b6..7151c092b 100644
--- a/util/src/main/java/org/aspectj/util/LangUtil.java
+++ b/util/src/main/java/org/aspectj/util/LangUtil.java
@@ -57,6 +57,8 @@ public class LangUtil {
static {
// http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html
// http://openjdk.java.net/jeps/223 "New Version-String Scheme"
+ // TODO: Use java.lang.Runtime class (since Java 9, now AspectJ needs Java 11+ due to JDT Core anyway)
+ final String JAVA_VERSION_NOT_FOUND = "System properties appear damaged, cannot find: java.version/java.runtime.version/java.vm.version";
try {
String vm = System.getProperty("java.version"); // JLS 20.18.7
if (vm == null) {
@@ -66,15 +68,12 @@ public class LangUtil {
vm = System.getProperty("java.vm.version");
}
if (vm == null) {
- new RuntimeException(
- "System properties appear damaged, cannot find: java.version/java.runtime.version/java.vm.version")
- .printStackTrace(System.err);
+ new RuntimeException(JAVA_VERSION_NOT_FOUND).printStackTrace(System.err);
vmVersion = 1.5;
} else {
- // Version: [1-9][0-9]*((\.0)*\.[1-9][0-9]*)*
// Care about the first set of digits and second set if first digit is 1
try {
- List<Integer> numbers = getFirstNumbers(vm);
+ List<Integer> numbers = getJavaMajorMinor(vm);
if (numbers.get(0) == 1) {
// Old school for 1.0 > 1.8
vmVersion = numbers.get(0)+(numbers.get(1)/10d);
@@ -89,16 +88,15 @@ public class LangUtil {
}
}
} catch (Throwable t) {
- new RuntimeException(
- "System properties appear damaged, cannot find: java.version/java.runtime.version/java.vm.version", t)
- .printStackTrace(System.err);
+ new RuntimeException(JAVA_VERSION_NOT_FOUND, t).printStackTrace(System.err);
vmVersion = 1.5;
}
}
- private static List<Integer> getFirstNumbers(String vm) {
+ private static List<Integer> getJavaMajorMinor(String vm) {
List<Integer> result = new ArrayList<>();
- StringTokenizer st = new StringTokenizer(vm,".-_");
+ // Can be something like '1.5', '11.0.16.1', '19+36-2238'
+ StringTokenizer st = new StringTokenizer(vm.replaceFirst("[+].*", ""), ".-_");
try {
result.add(Integer.parseInt(st.nextToken()));
result.add(Integer.parseInt(st.nextToken()));
@@ -106,6 +104,9 @@ public class LangUtil {
// NoSuchElementException if no more tokens
// NumberFormatException if not a number
}
+ // Always add a default minor, just in case a caller expects it
+ if (result.size() == 1)
+ result.add(0);
return result;
}
@@ -182,6 +183,10 @@ public class LangUtil {
return 19 <= vmVersion;
}
+ public static boolean is20VMOrGreater() {
+ return 20 <= vmVersion;
+ }
+
/**
* Shorthand for "if null, throw IllegalArgumentException"
*