[tomcat] branch master updated: Drop some reflection

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[tomcat] branch master updated: Drop some reflection

Rémy Maucherat
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 5ac227d  Drop some reflection
5ac227d is described below

commit 5ac227ded1eb966daddcaf4b5b22ae0b8a17b697
Author: remm <[hidden email]>
AuthorDate: Thu Feb 18 23:29:37 2021 +0100

    Drop some reflection
---
 .../apache/catalina/loader/LocalStrings.properties |  1 -
 java/org/apache/catalina/loader/WebappLoader.java  | 28 +++++++++-------------
 2 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/java/org/apache/catalina/loader/LocalStrings.properties b/java/org/apache/catalina/loader/LocalStrings.properties
index dee7e2c..7c6c976 100644
--- a/java/org/apache/catalina/loader/LocalStrings.properties
+++ b/java/org/apache/catalina/loader/LocalStrings.properties
@@ -59,7 +59,6 @@ webappClassLoader.wrongVersion=(unable to load class [{0}])
 webappClassLoaderParallel.registrationFailed=Registration of org.apache.catalina.loader.ParallelWebappClassLoader as capable of loading classes in parallel failed
 
 webappLoader.deploy=Deploying class repositories to work directory [{0}]
-webappLoader.noJakartaConverter=The Jakarta converter provided by the Tomcat migration tool could not be loaded
 webappLoader.noResources=No resources found for context [{0}]
 webappLoader.reloadable=Cannot set reloadable property to [{0}]
 webappLoader.setContext.ise=Setting the Context is not permitted while the loader is started.
diff --git a/java/org/apache/catalina/loader/WebappLoader.java b/java/org/apache/catalina/loader/WebappLoader.java
index 33aad92..7e1405a 100644
--- a/java/org/apache/catalina/loader/WebappLoader.java
+++ b/java/org/apache/catalina/loader/WebappLoader.java
@@ -24,7 +24,6 @@ import java.io.IOException;
 import java.lang.instrument.ClassFileTransformer;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.nio.charset.StandardCharsets;
@@ -42,6 +41,8 @@ import org.apache.catalina.util.LifecycleMBeanBase;
 import org.apache.catalina.util.ToStringUtil;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.jakartaee.ClassConverter;
+import org.apache.tomcat.jakartaee.EESpecProfile;
 import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.buf.UDecoder;
 import org.apache.tomcat.util.compat.JreCompat;
@@ -366,24 +367,17 @@ public class WebappLoader extends LifecycleMBeanBase implements Loader{
 
             // Set Jakarta class converter
             if (getJakartaConverter() != null) {
+                ClassFileTransformer transformer = null;
                 try {
-                    ClassFileTransformer transformer = null;
-                    try {
-                        Class<?> jakartaEnumClass = Class.forName("org.apache.tomcat.jakartaee.EESpecProfile");
-                        Method valueOf = jakartaEnumClass.getMethod("valueOf", String.class);
-                        Object profile = valueOf.invoke(null, getJakartaConverter());
-                        transformer =
-                                (ClassFileTransformer) Class.forName("org.apache.tomcat.jakartaee.ClassConverter")
-                                .getConstructor(jakartaEnumClass).newInstance(profile);
-                    } catch (InvocationTargetException | NoSuchMethodException ignored) {
-                        // Use default value with no argument constructor
-                        transformer =
-                                (ClassFileTransformer) Class.forName("org.apache.tomcat.jakartaee.ClassConverter").newInstance();
-                    }
-                    classLoader.addTransformer(transformer);
-                } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
-                    log.warn(sm.getString("webappLoader.noJakartaConverter"), e);
+                    EESpecProfile profile = EESpecProfile.valueOf(getJakartaConverter());
+                    // FIXME: transformer = new ClassConverter(profile); after 0.2
+                    transformer =
+                            (ClassFileTransformer) ClassConverter.class.getConstructor(EESpecProfile.class).newInstance(profile);
+                } catch (InvocationTargetException | NoSuchMethodException | IllegalArgumentException ignored) {
+                    // Use default value with no argument constructor
+                    transformer = new ClassConverter();
                 }
+                classLoader.addTransformer(transformer);
             }
 
             // Configure our repositories


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]