aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2022-10-05 10:11:54 +0200
committerAlexander Kriegisch <Alexander@Kriegisch.name>2022-10-05 10:11:54 +0200
commit0ff75f28fe7a0b7b4757c02b533704354c1dd46c (patch)
tree4164ab4127c3933df06710470110bf5d727faeaf
parent8cbfedcde9cda3f09784ff7fae2b1981154e0488 (diff)
downloadaspectj-0ff75f28fe7a0b7b4757c02b533704354c1dd46c.tar.gz
aspectj-0ff75f28fe7a0b7b4757c02b533704354c1dd46c.zip
LangUtil: improve Java version major/minor parsing
- Ignore everything including and after '+' in versions like '19+36-2238' - Add minor '.0' to Java versions like '19', '19+36-2238' Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
-rw-r--r--util/src/main/java/org/aspectj/util/LangUtil.java7
1 files changed, 4 insertions, 3 deletions
diff --git a/util/src/main/java/org/aspectj/util/LangUtil.java b/util/src/main/java/org/aspectj/util/LangUtil.java
index 02aa7d94b..7151c092b 100644
--- a/util/src/main/java/org/aspectj/util/LangUtil.java
+++ b/util/src/main/java/org/aspectj/util/LangUtil.java
@@ -96,16 +96,17 @@ public class LangUtil {
private static List<Integer> getJavaMajorMinor(String vm) {
List<Integer> result = new ArrayList<>();
// Can be something like '1.5', '11.0.16.1', '19+36-2238'
- StringTokenizer st = new StringTokenizer(vm,".-_+");
+ StringTokenizer st = new StringTokenizer(vm.replaceFirst("[+].*", ""), ".-_");
try {
result.add(Integer.parseInt(st.nextToken()));
- // FIXME: The minor will be wrong for version strings like '19+36-2238'.
- // The minor is only relevant for Java <= 1.8. Even so, this is super ugly.
result.add(Integer.parseInt(st.nextToken()));
} catch (Exception e) {
// 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;
}