This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 4c70a12e8a Remove deprecated code 4c70a12e8a is described below commit 4c70a12e8aac4081a11f200a7e70f0db30a6c79b Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Jan 23 20:39:14 2023 +0000 Remove deprecated code --- .../catalina/loader/WebappClassLoaderBase.java | 4 - .../TomcatURLStreamHandlerFactory.java | 169 --------------------- .../TomcatURLStreamHandlerProvider.java | 11 +- .../TestTomcatURLStreamHandlerFactory.java | 41 ----- 4 files changed, 2 insertions(+), 223 deletions(-) diff --git a/java/org/apache/catalina/loader/WebappClassLoaderBase.java b/java/org/apache/catalina/loader/WebappClassLoaderBase.java index 1111d8edd4..c334e1bf19 100644 --- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java +++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java @@ -1492,7 +1492,6 @@ public abstract class WebappClassLoaderBase extends URLClassLoader /** * Clear references. */ - @SuppressWarnings("deprecation") protected void clearReferences() { // If the JVM is shutting down, skip the memory leak checks @@ -1543,9 +1542,6 @@ public abstract class WebappClassLoaderBase extends URLClassLoader // Clear the classloader reference in the VM's bean introspector java.beans.Introspector.flushCaches(); - - // Clear any custom URLStreamHandlers - org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.release(this); } diff --git a/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java b/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java deleted file mode 100644 index 830858e774..0000000000 --- a/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.catalina.webresources; - -import java.net.URL; -import java.net.URLStreamHandler; -import java.net.URLStreamHandlerFactory; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -/** - * @deprecated Unused. Use the ServiceLoader mechanism to define additional - * handlers. Will be removed in Tomcat 11 onwards. - */ -@Deprecated -public class TomcatURLStreamHandlerFactory implements URLStreamHandlerFactory { - - // Singleton instance - private static volatile TomcatURLStreamHandlerFactory instance = null; - - /** - * Obtain a reference to the singleton instance. It is recommended that - * callers check the value of {@link #isRegistered()} before using the - * returned instance. - * - * @return A reference to the singleton instance - */ - public static TomcatURLStreamHandlerFactory getInstance() { - getInstanceInternal(true); - return instance; - } - - - private static TomcatURLStreamHandlerFactory getInstanceInternal(boolean register) { - // Double checked locking. OK because instance is volatile. - if (instance == null) { - synchronized (TomcatURLStreamHandlerFactory.class) { - if (instance == null) { - instance = new TomcatURLStreamHandlerFactory(register); - } - } - } - return instance; - } - - - private final boolean registered; - - // List of factories for application defined stream handler factories. - private final List<URLStreamHandlerFactory> userFactories = - new CopyOnWriteArrayList<>(); - - /** - * Register this factory with the JVM. May be called more than once. The - * implementation ensures that registration only occurs once. - * - * @return <code>true</code> if the factory is already registered with the - * JVM or was successfully registered as a result of this call. - * <code>false</code> if the factory was disabled prior to this - * call. - */ - public static boolean register() { - return getInstanceInternal(true).isRegistered(); - } - - - /** - * Prevent this this factory from registering with the JVM. May be called - * more than once. - * - * @return <code>true</code> if the factory is already disabled or was - * successfully disabled as a result of this call. - * <code>false</code> if the factory was already registered prior - * to this call. - */ - public static boolean disable() { - return !getInstanceInternal(false).isRegistered(); - } - - - /** - * Release references to any user provided factories that have been loaded - * using the provided class loader. Called during web application stop to - * prevent memory leaks. - * - * @param classLoader The class loader to release - */ - public static void release(ClassLoader classLoader) { - if (instance == null) { - return; - } - List<URLStreamHandlerFactory> factories = instance.userFactories; - for (URLStreamHandlerFactory factory : factories) { - ClassLoader factoryLoader = factory.getClass().getClassLoader(); - while (factoryLoader != null) { - if (classLoader.equals(factoryLoader)) { - // Implementation note: userFactories is a - // CopyOnWriteArrayList, so items are removed with - // List.remove() instead of usual Iterator.remove() - factories.remove(factory); - break; - } - factoryLoader = factoryLoader.getParent(); - } - } - } - - - private TomcatURLStreamHandlerFactory(boolean register) { - // Hide default constructor - // Singleton pattern to ensure there is only one instance of this - // factory - this.registered = register; - if (register) { - URL.setURLStreamHandlerFactory(this); - } - } - - - public boolean isRegistered() { - return registered; - } - - - /** - * Since the JVM only allows a single call to - * {@link URL#setURLStreamHandlerFactory(URLStreamHandlerFactory)} and - * Tomcat needs to register a handler, provide a mechanism to allow - * applications to register their own handlers. - * - * @param factory The user provided factory to add to the factories Tomcat - * has already registered - */ - public void addUserFactory(URLStreamHandlerFactory factory) { - userFactories.add(factory); - } - - - @Override - public URLStreamHandler createURLStreamHandler(String protocol) { - - - // Application handlers - for (URLStreamHandlerFactory factory : userFactories) { - URLStreamHandler handler = - factory.createURLStreamHandler(protocol); - if (handler != null) { - return handler; - } - } - - // Unknown protocol - return null; - } -} diff --git a/java/org/apache/catalina/webresources/TomcatURLStreamHandlerProvider.java b/java/org/apache/catalina/webresources/TomcatURLStreamHandlerProvider.java index 971e5ea4f8..6be9781506 100644 --- a/java/org/apache/catalina/webresources/TomcatURLStreamHandlerProvider.java +++ b/java/org/apache/catalina/webresources/TomcatURLStreamHandlerProvider.java @@ -21,18 +21,11 @@ import java.net.spi.URLStreamHandlerProvider; import org.apache.catalina.webresources.war.Handler; -@SuppressWarnings("deprecation") public class TomcatURLStreamHandlerProvider extends URLStreamHandlerProvider { private static final String WAR_PROTOCOL = "war"; private static final String CLASSPATH_PROTOCOL = "classpath"; - static { - // Create an instance without calling URL.setURLStreamHandlerFactory - TomcatURLStreamHandlerFactory.disable(); - } - - @Override public URLStreamHandler createURLStreamHandler(String protocol) { if (WAR_PROTOCOL.equals(protocol)) { @@ -41,7 +34,7 @@ public class TomcatURLStreamHandlerProvider extends URLStreamHandlerProvider { return new ClasspathURLStreamHandler(); } - // Possible user handler defined via Tomcat's custom API - return TomcatURLStreamHandlerFactory.getInstance().createURLStreamHandler(protocol); + + return null; } } diff --git a/test/org/apache/catalina/webresources/TestTomcatURLStreamHandlerFactory.java b/test/org/apache/catalina/webresources/TestTomcatURLStreamHandlerFactory.java deleted file mode 100644 index ac5b6342ff..0000000000 --- a/test/org/apache/catalina/webresources/TestTomcatURLStreamHandlerFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.catalina.webresources; - -import java.net.URLStreamHandler; -import java.net.URLStreamHandlerFactory; - -import org.junit.Test; - -/** - * @deprecated Code under test is deprecated and will be removed in Tomcat 11 - */ -@Deprecated -public class TestTomcatURLStreamHandlerFactory { - - @Test - public void testUserFactory() throws Exception { - URLStreamHandlerFactory factory = new URLStreamHandlerFactory() { - @Override - public URLStreamHandler createURLStreamHandler(String protocol) { - return null; - } - }; - TomcatURLStreamHandlerFactory.getInstance().addUserFactory(factory); - TomcatURLStreamHandlerFactory.release(factory.getClass().getClassLoader()); - } -} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org