Use Runtime.version() instead of reflection

See gh-31444
pull/31456/head
dreis2211 2 years ago committed by Stephane Nicoll
parent 98eb21712f
commit b687e1c7ee

@ -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

@ -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;
}
}
}

Loading…
Cancel
Save