Skip to content

Commit

Permalink
Allow version detection of unknown versions if experimental mode is a…
Browse files Browse the repository at this point in the history
…ctivated.
  • Loading branch information
raphw committed Jan 10, 2019
1 parent c227f70 commit bf61bcd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions byte-buddy-dep/src/main/java/net/bytebuddy/ClassFileVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,21 @@ public static ClassFileVersion ofJavaVersionString(String javaVersionString) {
} else if (javaVersionString.equals("1.13") || javaVersionString.equals("13")) {
return JAVA_V13;
} else {
if (OpenedClassReader.EXPERIMENTAL) {
try {
int version = Integer.parseInt(javaVersionString.startsWith("1.")
? javaVersionString.substring(2)
: javaVersionString);
if (version > 0) {
return new ClassFileVersion(BASE_VERSION + version);
}
} catch (NumberFormatException ignored) {
}
}
throw new IllegalArgumentException("Unknown Java version string: " + javaVersionString);
}
}


/**
* Creates a class file version for a given major release of Java. Currently, all versions reaching from
* Java 1 to Java 9 are supported.
Expand Down Expand Up @@ -216,7 +226,11 @@ public static ClassFileVersion ofJavaVersion(int javaVersion) {
case 13:
return JAVA_V13;
default:
throw new IllegalArgumentException("Unknown Java version: " + javaVersion);
if (OpenedClassReader.EXPERIMENTAL && javaVersion > 0) {
return new ClassFileVersion(BASE_VERSION + javaVersion);
} else {
throw new IllegalArgumentException("Unknown Java version: " + javaVersion);
}
}
}

Expand Down

0 comments on commit bf61bcd

Please sign in to comment.