Skip to content

Commit

Permalink
Fixes MultiRelease JAR lookup for specific version classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ctabin committed Oct 21, 2023
1 parent 1a359f0 commit 02d73a7
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -621,15 +621,39 @@ private byte[] loadClassData0(final URLEntry res, final String entryName) {
res.setProtectionDomain(ASURLClassLoader.this, entry.getCertificates());
return classData;
}

if (zip.isMultiRelease()) {
String javaVersion = System.getProperty("java.version");
JarEntry multiVersionEntry = zip.getJarEntry("META-INF/versions/"+javaVersion+"/"+entryName);
if (multiVersionEntry != null) {
InputStream classStream = zip.getInputStream(multiVersionEntry);
byte[] classData = getClassData(classStream);
res.setProtectionDomain(ASURLClassLoader.this, multiVersionEntry.getCertificates());
return classData;
}
}
} else { // Its a directory....
File classFile = new File (res.file, entryName.replace('/', File.separatorChar));
String entryPath = entryName.replace('/', File.separatorChar);
File classFile = new File (res.file, entryPath);
if (classFile.exists()) {
try (InputStream classStream = new FileInputStream(classFile)) {
byte[] classData = getClassData(classStream);
res.setProtectionDomain(ASURLClassLoader.this, null);
return classData;
}
}

File multiVersionDir = new File(res.file, "META-INF/versions/");
if (multiVersionDir.exists()) {
File multiVersionClassFile = new File(multiVersionDir, entryPath);
if (multiVersionClassFile.exists()) {
try (InputStream classStream = new FileInputStream(multiVersionClassFile)) {
byte[] classData = getClassData(classStream);
res.setProtectionDomain(ASURLClassLoader.this, null);
return classData;
}
}
}
}
} catch (IOException ioe) {
_logger.log(Level.INFO, CULoggerInfo.exceptionInASURLClassLoader, ioe);
Expand Down

0 comments on commit 02d73a7

Please sign in to comment.