Merge pull request #31444 from dreis2211

* pr/31444:
  Use Runtime.version() instead of reflection

Closes gh-31444
This commit is contained in:
Stephane Nicoll
2022-06-19 10:30:04 +02:00
2 changed files with 2 additions and 27 deletions

View File

@@ -57,19 +57,7 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
private static final int BASE_VERSION = 8;
private static final int RUNTIME_VERSION;
static {
int version;
try {
Object runtimeVersion = Runtime.class.getMethod("version").invoke(null);
version = (int) runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion);
}
catch (Throwable ex) {
version = BASE_VERSION;
}
RUNTIME_VERSION = version;
}
private static final int RUNTIME_VERSION = Runtime.version().feature();
private static final long LOCAL_FILE_HEADER_SIZE = 30;
@@ -110,9 +98,6 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable<JarEntry> {
JarFileEntries(JarFile jarFile, JarEntryFilter filter) {
this.jarFile = jarFile;
this.filter = filter;
if (RUNTIME_VERSION == BASE_VERSION) {
this.multiReleaseJar = false;
}
}
@Override

View File

@@ -560,7 +560,7 @@ class JarFileTests {
assertThat(entry.getName()).isEqualTo("multi-release.dat");
InputStream inputStream = multiRelease.getInputStream(entry);
assertThat(inputStream.available()).isEqualTo(1);
assertThat(inputStream.read()).isEqualTo(getJavaVersion());
assertThat(inputStream.read()).isEqualTo(Runtime.version().feature());
}
}
@@ -732,14 +732,4 @@ class JarFileTests {
assertThatIllegalStateException().isThrownBy(throwingCallable).withMessage("zip file closed");
}
private int getJavaVersion() {
try {
Object runtimeVersion = Runtime.class.getMethod("version").invoke(null);
return (int) runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion);
}
catch (Throwable ex) {
return 8;
}
}
}