You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2022/04/25 14:52:29 UTC
[tomee] branch master updated: Quick and dirty fix for Tomcat NPE https://github.com/apache/tomcat/pull/505
This is an automated email from the ASF dual-hosted git repository.
jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/master by this push:
new 86bdf225c1 Quick and dirty fix for Tomcat NPE https://github.com/apache/tomcat/pull/505
86bdf225c1 is described below
commit 86bdf225c1bce93bac2a981277f8a92f26292891
Author: Jean-Louis Monteiro <jl...@tomitribe.com>
AuthorDate: Mon Apr 25 16:52:18 2022 +0200
Quick and dirty fix for Tomcat NPE
https://github.com/apache/tomcat/pull/505
---
.../apache/openejb/server/httpd/util/HttpUtil.java | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/util/HttpUtil.java b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/util/HttpUtil.java
index b07924baac..260347776a 100644
--- a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/util/HttpUtil.java
+++ b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/util/HttpUtil.java
@@ -33,6 +33,9 @@ import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
@@ -158,12 +161,29 @@ public final class HttpUtil {
final ClassLoader classLoader = ParentClassLoaderFinder.Helper.get();
final Class<?> jspFactory = classLoader.loadClass("org.apache.jasper.runtime.JspFactoryImpl");
final Class<?> jspFactoryApi = classLoader.loadClass("jakarta.servlet.jsp.JspFactory");
- jspFactoryApi.getMethod("setDefaultFactory", jspFactoryApi).invoke(null, jspFactory.newInstance());
+
+ final Object newInstance = jspFactory.newInstance();
+ jspFactoryApi.getMethod("setDefaultFactory", jspFactoryApi).invoke(null, newInstance);
+
+ // bug introduced in Tomcat with https://github.com/apache/tomcat/commit/5e8eb5533f551c3dbc3003e4c2f4f0d2958a8eb3
+ // should be eventually removed when fixed
+ final Class<?> jspInitializer = classLoader.loadClass("org.apache.jasper.servlet.JasperInitializer");
+ setFinalStatic(jspInitializer.getDeclaredField("defaultFactory"), newInstance);
} catch (final Throwable t) {
// no-op
}
}
+ static void setFinalStatic(final Field field, final Object newValue) throws Exception {
+ field.setAccessible(true);
+
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+
+ field.set(null, newValue);
+ }
+
private static ClassLoader setClassLoader(final WebContext wc, final Thread thread) {
final ClassLoader old = thread.getContextClassLoader();
thread.setContextClassLoader(wc.getClassLoader() == null ? wc.getAppContext().getClassLoader() : wc.getClassLoader());