From d35892c0c2dd9f0c5d1c9cd923d40651a9920260 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 11 Aug 2022 17:55:37 +1000 Subject: [PATCH] Issue #8447 Remove ELContextCleaner for ee10 --- .../servlet/listener/ELContextCleaner.java | 113 ------------------ .../src/main/config/etc/webdefault-ee10.xml | 8 -- 2 files changed, 121 deletions(-) delete mode 100644 jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/listener/ELContextCleaner.java diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/listener/ELContextCleaner.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/listener/ELContextCleaner.java deleted file mode 100644 index c50da21159a..00000000000 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/listener/ELContextCleaner.java +++ /dev/null @@ -1,113 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others. -// -// This program and the accompanying materials are made available under the -// terms of the Eclipse Public License v. 2.0 which is available at -// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -// which is available at https://www.apache.org/licenses/LICENSE-2.0. -// -// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -// ======================================================================== -// - -package org.eclipse.jetty.ee10.servlet.listener; - -import java.lang.reflect.Field; -import java.util.Iterator; -import java.util.Map; - -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletContextEvent; -import jakarta.servlet.ServletContextListener; -import org.eclipse.jetty.util.Loader; - -/** - * ELContextCleaner - * - * Clean up BeanELResolver when the context is going out - * of service: - * - * See http://java.net/jira/browse/GLASSFISH-1649 - * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=353095 - */ -public class ELContextCleaner implements ServletContextListener -{ - // IMPORTANT: This class cannot have a slf4j Logger - // As it will force this requirement on webapps. - // private static final Logger LOG = LoggerFactory.getLogger(ELContextCleaner.class); - - @Override - public void contextInitialized(ServletContextEvent sce) - { - } - - @Override - public void contextDestroyed(ServletContextEvent sce) - { - try - { - //Check that the BeanELResolver class is on the classpath - Class beanELResolver = Loader.loadClass("jakarta.el.BeanELResolver"); - - //Get a reference via reflection to the properties field which is holding class references - Field field = getField(beanELResolver); - - field.setAccessible(true); - - //Get rid of references - purgeEntries(sce.getServletContext(), field); - } - - catch (ClassNotFoundException e) - { - //BeanELResolver not on classpath, ignore - } - catch (SecurityException | IllegalArgumentException | IllegalAccessException e) - { - sce.getServletContext().log("Cannot purge classes from javax.el.BeanELResolver", e); - } - catch (NoSuchFieldException e) - { - sce.getServletContext().log("Not cleaning cached beans: no such field javax.el.BeanELResolver.properties"); - } - } - - protected Field getField(Class beanELResolver) - throws SecurityException, NoSuchFieldException - { - if (beanELResolver == null) - return null; - - return beanELResolver.getDeclaredField("properties"); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - protected void purgeEntries(ServletContext context, Field properties) - throws IllegalArgumentException, IllegalAccessException - { - if (properties == null) - return; - - Map map = (Map)properties.get(null); - if (map == null) - return; - - Iterator> itor = map.keySet().iterator(); - while (itor.hasNext()) - { - Class clazz = itor.next(); - context.log(String.format("Clazz: %s loaded by %s", clazz, clazz.getClassLoader())); - if (Thread.currentThread().getContextClassLoader().equals(clazz.getClassLoader())) - { - itor.remove(); - context.log("removed"); - } - else - { - context.log(String.format("not removed: contextClassLoader=%s class's classLoader=%s", - Thread.currentThread().getContextClassLoader(), clazz.getClassLoader())); - } - } - } -} diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/webdefault-ee10.xml b/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/webdefault-ee10.xml index 880e3fc0f69..f7bfb84bd2f 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/webdefault-ee10.xml +++ b/jetty-ee10/jetty-ee10-webapp/src/main/config/etc/webdefault-ee10.xml @@ -28,14 +28,6 @@ Default web.xml file. This file is applied to a Web application before its own WEB_INF/web.xml file - - - - - - - org.eclipse.jetty.ee10.servlet.listener.ELContextCleaner -