diff --git a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/LogFacade.java b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/LogFacade.java index a34a8318bd0..efa0a0d7b85 100644 --- a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/LogFacade.java +++ b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/LogFacade.java @@ -104,6 +104,11 @@ public static String getString(String key, Object... objects) { level = "WARNING") public static final String CHECK_THREAD_LOCALS_FOR_LEAKS_FAIL = PREFIX + "00011"; + @LogMessageInfo( + message = "Finding ThreadLocal references for web application [{0}] is not supported by the JVM. Use '--add-opens java.base/java.lang=ALL-UNNAMED' java argument to enable it", + level = "FINE") + public static final String CHECK_THREAD_LOCALS_FOR_LEAKS_NOT_SUPPORTED = PREFIX + "00012"; + @LogMessageInfo( message = "The web application [{0}] created a ThreadLocal with key of [{1}]" + " but failed to remove it when the web application was stopped." diff --git a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/ReferenceCleaner.java b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/ReferenceCleaner.java index e2586085191..f4cb10339e0 100644 --- a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/ReferenceCleaner.java +++ b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/ReferenceCleaner.java @@ -44,6 +44,8 @@ import static org.glassfish.web.loader.LogFacade.CHECK_THREAD_LOCALS_FOR_LEAKS_KEY; import static org.glassfish.web.loader.LogFacade.getString; +import java.lang.reflect.InaccessibleObjectException; + class ReferenceCleaner { private static final Logger LOG = LogFacade.getSysLogger(ReferenceCleaner.class); @@ -143,6 +145,9 @@ private void checkThreadLocalsForLeaks() { checkThreadLocalMapForLeaks(inheritableMap, tableField); } } + } catch (InaccessibleObjectException e) { + // module java.base does not "opens java.lang" + LOG.log(WARNING, getString(LogFacade.CHECK_THREAD_LOCALS_FOR_LEAKS_NOT_SUPPORTED, loader.getName())); } catch (Exception e) { LOG.log(WARNING, getString(LogFacade.CHECK_THREAD_LOCALS_FOR_LEAKS_FAIL, loader.getName()), e); } 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 5c3517c8ef9..5213898a328 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 @@ -85,6 +85,8 @@ import static org.glassfish.web.loader.LogFacade.UNSUPPORTED_VERSION; import static org.glassfish.web.loader.LogFacade.getString; +import org.apache.naming.resources.BaseDirContext; + /** * Specialized web application class loader. *

@@ -313,6 +315,9 @@ public void setResources(DirContext resources) { dirCtx = proxyRes.getDirContext(); } else { dirCtx = resources; + if (dirCtx instanceof BaseDirContext) { + contextName = new File(((BaseDirContext)dirCtx).getDocBase()).getName(); + } } if (dirCtx instanceof WebDirContext) { ((WebDirContext) dirCtx).setJarFileResourcesProvider(this);