From dac70f4cb1aaac4c5cbf3a87b1e9e4aa54a3a9e0 Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Wed, 13 Nov 2024 14:17:54 +0000 Subject: [PATCH 1/2] FISH-10136 Add fallout for if field doesn't exist Signed-off-by: Andrew Pielage --- .../org/glassfish/web/loader/WebappClassLoader.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 d8e665518f9..898d2e45dd6 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 @@ -2673,8 +2673,16 @@ private void clearBeanELResolverCache() { 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); + + Field field = CachingReflectionUtil.getFieldFromCache(elUtilsClass, "BEAN_RESOLVER", false); + if (field == null) { + logger.log(Level.FINE, "Could not find BEAN_RESOLVER field on {0}", elUtilsClass.getName()); + return; + } + + // TODO: Review whether this is still required; Mojarra may have fixed this themselves in PR#5479? + // Is there solution enough? Do we need to retain this for cases where another Faces implementation is being provided? + Object resolver = field.get(null); if (resolver != null && elResolverClass.isPresent()) { logger.fine(String.format("Fields: %s", Arrays.stream(elResolverClass.get().getDeclaredFields()) .map(Field::toString).collect(Collectors.toList()))); From dc83a6a273230782a92a410784279d088f455c71 Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Tue, 26 Nov 2024 16:52:57 +0000 Subject: [PATCH 2/2] FISH-10136 Remove now redundant code Mojarra handles this itself now, we should no longer need this on our side Signed-off-by: Andrew Pielage --- .../web/loader/WebappClassLoader.java | 64 ------------------- 1 file changed, 64 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 898d2e45dd6..93578a1a19a 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 @@ -2051,7 +2051,6 @@ public void stop() throws Exception { // START SJSAS 6258619 ClassLoaderUtil.releaseLoader(this); // END SJSAS 6258619 - clearBeanELResolverCache(); clearJaxRSCache(); synchronized(jarFilesLock) { @@ -2659,69 +2658,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)); - - Field field = CachingReflectionUtil.getFieldFromCache(elUtilsClass, "BEAN_RESOLVER", false); - if (field == null) { - logger.log(Level.FINE, "Could not find BEAN_RESOLVER field on {0}", elUtilsClass.getName()); - return; - } - - // TODO: Review whether this is still required; Mojarra may have fixed this themselves in PR#5479? - // Is there solution enough? Do we need to retain this for cases where another Faces implementation is being provided? - Object resolver = field.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