From 43d6dd699b09a2e407e361faaa21a8c35ab381cc Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Wed, 27 Nov 2024 10:02:40 +0000 Subject: [PATCH] Merge pull request #7065 from Pandrex247/FISH-10136-Fix-Micro-NPE FISH-10136 Fix NPE in Payara Micro and Embedded --- .../web/loader/WebappClassLoader.java | 56 ------------------- 1 file changed, 56 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 ff57d803f2d..b741e65db46 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 @@ -2052,7 +2052,6 @@ public void stop() throws Exception { // START SJSAS 6258619 ClassLoaderUtil.releaseLoader(this); // END SJSAS 6258619 - clearBeanELResolverCache(); clearJaxRSCache(); synchronized(jarFilesLock) { @@ -2660,61 +2659,6 @@ private void clearReferencesRmiTargets() { } } - private void clearBeanELResolverCache() { - try { - Class elUtilsClass = CachingReflectionUtil.getClassFromCache("com.sun.faces.el.ELUtils", this); - if (elUtilsClass != null) { - clearBeanResolver(elUtilsClass); - } - } catch (Exception e) { - logger.log(Level.WARNING, "Error clearing BeanELResolver cache", e); - } - } - - private void clearBeanResolver(Class elUtilsClass) throws Exception { - Optional> elResolverClass = Optional.ofNullable(CachingReflectionUtil - .getClassFromCache("jakarta.el.BeanELResolver", this)); - Object resolver = CachingReflectionUtil.getFieldFromCache(elUtilsClass, "BEAN_RESOLVER", - false).get(null); - if (resolver != null && elResolverClass.isPresent()) { - logger.fine(String.format("Fields: %s", Arrays.stream(elResolverClass.get().getDeclaredFields()) - .map(Field::toString).collect(Collectors.toList()))); - Method clearPropertiesMethod = CachingReflectionUtil.getMethodFromCache(elResolverClass.get(), - "clearProperties", false, ClassLoader.class); - if (clearPropertiesMethod != null) { - clearPropertiesMethod.invoke(resolver, this); - } else { - clearBeanELResolverPropertiesCache(resolver, elResolverClass.get()); - } - } else { - logger.warning("BeanELResolver not found"); - } - } - - /** - * Workaround until clearProperties() is available in Jakarta EL - * @see Jakarta EL Pull Request - */ - private void clearBeanELResolverPropertiesCache(Object resolver, Class elResolverClass) throws Exception { - Optional> elResolverCacheClass = Optional.ofNullable(CachingReflectionUtil - .getClassFromCache("jakarta.el.BeanELResolver$SoftConcurrentHashMap", this)); - var propertiesField = Optional.ofNullable(CachingReflectionUtil - .getFieldFromCache(elResolverClass, "properties", true)); - @SuppressWarnings("unchecked") - ConcurrentHashMap, Object> properties = - (ConcurrentHashMap, Object>) propertiesField.get().get(resolver); - properties.entrySet().removeIf(entry -> entry.getKey().getClassLoader() == this); - var mapField = Optional.ofNullable(CachingReflectionUtil - .getFieldFromCache(elResolverCacheClass.get(), "map", true)); - @SuppressWarnings("unchecked") - ConcurrentHashMap, Object> map = - (ConcurrentHashMap, Object>) mapField.get().get(propertiesField.get().get(resolver)); - map.entrySet().removeIf(entry -> entry.getKey().getClassLoader() == this); - var cleanupMethod = Optional.ofNullable(CachingReflectionUtil - .getMethodFromCache(elResolverCacheClass.get(), "cleanup", true)); - cleanupMethod.get().invoke(propertiesField.get().get(resolver)); - } - private void clearJaxRSCache() { try { Class cdiComponentProvider = CachingReflectionUtil