From 639fe4fdeaa217f8b867989608cb094ec15b2706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mat=C4=9Bj=C4=8Dek?= Date: Fri, 1 Jul 2022 10:35:38 +0200 Subject: [PATCH] el-api 5.0.1 now avoids memory leaks - so there is no need to use the reflection to clear the cache - also it would not work any more as the field is not static now) --- .../web/loader/WebappClassLoader.java | 95 +++---------------- nucleus/parent/pom.xml | 2 +- 2 files changed, 15 insertions(+), 82 deletions(-) diff --git a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/WebappClassLoader.java b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/WebappClassLoader.java index 955a6237b8e..58025618bd9 100644 --- a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/WebappClassLoader.java +++ b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/WebappClassLoader.java @@ -1615,24 +1615,16 @@ public void preDestroy() { /** * Stop the class loader. * - * @exception LifecycleException if a lifecycle error occurs + * @throws LifecycleException if a lifecycle error occurs */ public void stop() throws Exception { - if (!started) { return; } - // START GlassFish Issue 587 - purgeELBeanClasses(); - // END GlassFish Issue 587 - - /* - * Clearing references should be done before setting started to - * false, due to possible side effects. - * In addition, set this classloader as the Thread's context - * classloader, see IT 9894 for details - */ + // Clearing references should be done before setting started to + // false, due to possible side effects. + // In addition, set this classloader as the Thread's context classloader ClassLoader curCl = null; try { curCl = Thread.currentThread().getContextClassLoader(); @@ -1644,9 +1636,7 @@ public void stop() throws Exception { } } - // START SJSAS 6258619 close(); - // END SJSAS 6258619 started = false; @@ -3001,80 +2991,23 @@ protected static void deleteDir(File dir) { } - // START SJSAS 6344989 public void addByteCodePreprocessor(BytecodePreprocessor preprocessor) { byteCodePreprocessors.add(preprocessor); } - // END SJSAS 6344989 - // START GlassFish Issue 587 - /* - * Purges all bean classes that were loaded by this WebappClassLoader - * from the caches maintained by jakarta.el.BeanELResolver, in order to - * avoid this WebappClassLoader from leaking. - */ - private void purgeELBeanClasses() { - - Field fieldlist[] = jakarta.el.BeanELResolver.class.getDeclaredFields(); - for (Field fld : fieldlist) { - if (fld.getName().equals("properties")) { - purgeELBeanClasses(fld); - break; - } - } - } - - /* - * Purges all bean classes that were loaded by this WebappClassLoader - * from the cache represented by the given reflected field. + /** + * Create and return a temporary loader with the same visibility + * as this loader. The temporary loader may be used to load + * resources or any other application classes for the purposes of + * introspecting them for annotations. The persistence provider + * should not maintain any references to the temporary loader, + * or any objects loaded by it. * - * @param fld The reflected field from which to remove the bean classes - * that were loaded by this WebappClassLoader + * @return A temporary classloader with the same classpath as this loader */ - private void purgeELBeanClasses(final Field fld) { - - setAccessible(fld); - - Map m = null; - try { - m = getBeanELResolverProperties(fld); - } catch (IllegalAccessException iae) { - logger.log(Level.WARNING, LogFacade.UNABLE_PURGE_BEAN_CLASSES, iae); - return; - } - - if (m.size() == 0) { - return; - } - - Iterator iter = m.keySet().iterator(); - while (iter.hasNext()) { - Class mbeanClass = iter.next(); - if (this.equals(mbeanClass.getClassLoader())) { - iter.remove(); - } - } - } - - @SuppressWarnings("unchecked") - private static Map getBeanELResolverProperties(Field fld) throws IllegalAccessException { - return (Map)fld.get(null); - } - // END GlassFish Issue 587 - - /** - * Create and return a temporary loader with the same visibility - * as this loader. The temporary loader may be used to load - * resources or any other application classes for the purposes of - * introspecting them for annotations. The persistence provider - * should not maintain any references to the temporary loader, - * or any objects loaded by it. - * - * @return A temporary classloader with the same classpath as this loader - */ - @Override - public ClassLoader copy() { + @Override + public ClassLoader copy() { logger.entering("WebModuleListener$InstrumentableWebappClassLoader", "copy"); // set getParent() as the parent of the cloned class loader return AccessController.doPrivileged(new PrivilegedAction() { diff --git a/nucleus/parent/pom.xml b/nucleus/parent/pom.xml index 5b12189100c..41029b92296 100644 --- a/nucleus/parent/pom.xml +++ b/nucleus/parent/pom.xml @@ -73,7 +73,7 @@ - 5.0.0 + 5.0.1 5.0.0-M2