From fb96e517da6dd50b8d841af170951c4d090ebaed Mon Sep 17 00:00:00 2001 From: lprimak Date: Tue, 4 Jun 2024 14:21:04 -0700 Subject: [PATCH] bugfix: optimize MR-jar processing and remove resource liak from JarFile remaining open --- .../com/sun/enterprise/loader/ASURLClassLoader.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 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 fe088499103..4f131b54612 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-2023] [Payara Foundation and/or its affiliates] + // Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] package com.sun.enterprise.loader; @@ -95,6 +95,7 @@ These variables cannot be nulled out because of this, but the contents are clear /** logger for this class */ private static final Logger _logger = CULoggerInfo.getLogger(); + private static final Runtime.Version RUNTIME_VERSION = Runtime.Version.parse(System.getProperty("java.version")); /* list of url entries of this class loader. Using LinkedHashSet instead of original ArrayList @@ -613,12 +614,9 @@ private byte[] loadClassData0(final URLEntry res, final String entryName) { return AccessController.doPrivileged((PrivilegedAction) () -> { try { if (res.isJar) { // It is a jarfile.. - JarFile zip = res.zip; - JarFile jar = new JarFile(res.file, false, JarFile.OPEN_READ, - Runtime.Version.parse(System.getProperty("java.version"))); - JarEntry entry = jar.getJarEntry(entryName); + JarEntry entry = res.zip.getJarEntry(entryName); if (entry != null) { - byte[] classData = getClassData(zip.getInputStream(entry)); + byte[] classData = getClassData(res.zip.getInputStream(entry)); res.setProtectionDomain(ASURLClassLoader.this, entry.getCertificates()); return classData; } @@ -899,7 +897,7 @@ private static final class ProtectedJarFile extends JarFile { * @throws IOException from parent */ public ProtectedJarFile(File file) throws IOException { - super(file); + super(file, true, OPEN_READ, RUNTIME_VERSION); registerCloseEvent(); }