From 02d73a7e51d4b78902f14a4f31b92b7f7b724966 Mon Sep 17 00:00:00 2001 From: Cedric Tabin Date: Sat, 21 Oct 2023 17:40:33 +0200 Subject: [PATCH 1/2] Fixes MultiRelease JAR lookup for specific version classes --- .../enterprise/loader/ASURLClassLoader.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java index 53fa2758fba..2afc4f1a306 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java @@ -621,8 +621,20 @@ 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); @@ -630,6 +642,18 @@ private byte[] loadClassData0(final URLEntry res, final String entryName) { 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); From 34153c8741382e051df38717b92b07905837bf4b Mon Sep 17 00:00:00 2001 From: Alfonso Altamirano Date: Fri, 27 Oct 2023 14:30:13 -0600 Subject: [PATCH 2/2] FISH-7959: simplifying multi-release jar processing --- .../enterprise/loader/ASURLClassLoader.java | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java index 2afc4f1a306..fe088499103 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ - // Portions Copyright [2016-2020] [Payara Foundation and/or its affiliates] + // Portions Copyright [2016-2023] [Payara Foundation and/or its affiliates] package com.sun.enterprise.loader; @@ -614,24 +614,14 @@ private byte[] loadClassData0(final URLEntry res, final String entryName) { try { if (res.isJar) { // It is a jarfile.. JarFile zip = res.zip; - JarEntry entry = zip.getJarEntry(entryName); + JarFile jar = new JarFile(res.file, false, JarFile.OPEN_READ, + Runtime.Version.parse(System.getProperty("java.version"))); + JarEntry entry = jar.getJarEntry(entryName); if (entry != null) { - InputStream classStream = zip.getInputStream(entry); - byte[] classData = getClassData(classStream); + byte[] classData = getClassData(zip.getInputStream(entry)); 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.... String entryPath = entryName.replace('/', File.separatorChar); File classFile = new File (res.file, entryPath);