[
https://issues.apache.org/jira/browse/WW-5101?focusedWorklogId=527661&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-527661
]
ASF GitHub Bot logged work on WW-5101:
--------------------------------------
Author: ASF GitHub Bot
Created on: 23/Dec/20 14:38
Start Date: 23/Dec/20 14:38
Worklog Time Spent: 10m
Work Description: sepe81 commented on a change in pull request #460:
URL: https://github.com/apache/struts/pull/460#discussion_r547989077
##########
File path:
core/src/main/java/com/opensymphony/xwork2/util/AbstractLocalizedTextProvider.java
##########
@@ -308,36 +305,90 @@ protected void reloadBundles(Map<String, Object> context)
{
}
}
+ /**
+ * A helper method for {@link ResourceBundle} bundle reload logic.
+ *
+ * Uses standard {@link ResourceBundle} methods to clear the bundle caches
for the
+ * {@link ClassLoader} instances that this class is aware of at the time
of the call.
+ *
+ * The <code>clearCache()</code> methods have been available since Java
1.6, so
+ * it is anticipated the logic will work on any subsequent JVM versions.
+ *
+ * @since 2.6
+ */
+ private void clearResourceBundleClassloaderCaches() {
+ final ClassLoader ccl = getCurrentThreadContextClassLoader();
+ ResourceBundle.clearCache(); // Bundles loaded by the caller's
classloader.
+ ResourceBundle.clearCache(ccl); // Bundles loaded by the context
classloader (may be the same).
+ // Clear the bundle cache for any non-null delegated classloaders.
+ delegatedClassLoaderMap.forEach( (key, value) -> { if (value != null)
ResourceBundle.clearCache(value) ;} );
+ }
+
+ /**
+ * "Hacky" helper method that attempts to clear the Tomcat
<code>ResourceEntry</code>
+ * {@link Map} using knowledge of the Tomcat source code.
+ *
+ * It relies on the {@link #TOMCAT_RESOURCE_ENTRIES_FIELD} field name,
base class name
+ * {@link #TOMCAT_WEBAPP_CLASSLOADER_BASE}. and descendant class names
{@link #TOMCAT_WEBAPP_CLASSLOADER},
+ * {@link #TOMCAT_PARALLEL_WEBAPP_CLASSLOADER}, to keep the values
identified in the constants.
+ * It appears to be valid for Tomcat versions 7-10 so far, but could
become invalid at any time in the future
+ * when the resource handling logic in Tomcat changes.
+ *
+ * Note: With Java 9+, calling this method may result in "Illegal
reflective access" warnings. Be aware
+ * its logic may fail in a future version of Java that blocks the
reflection calls needed for this method.
+ * {<code></code>
+ */
private void clearTomcatCache() {
ClassLoader loader = getCurrentThreadContextClassLoader();
// no need for compilation here.
Class cl = loader.getClass();
+ Class superCl = cl.getSuperclass();
try {
- if
("org.apache.catalina.loader.WebappClassLoader".equals(cl.getName())) {
- clearMap(cl, loader, TOMCAT_RESOURCE_ENTRIES_FIELD);
+ if ( (TOMCAT_WEBAPP_CLASSLOADER.equals(cl.getName()) ||
TOMCAT_PARALLEL_WEBAPP_CLASSLOADER.equals(cl.getName())) &&
+ (superCl != null &&
TOMCAT_WEBAPP_CLASSLOADER_BASE.equals(superCl.getName())) ) {
Review comment:
```suggestion
(superCl != null &&
TOMCAT_WEBAPP_CLASSLOADER_BASE.equals(superCl.getName()))) {
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 527661)
Time Spent: 1h (was: 50m)
> AbstractLocalizedTextProvider illegal reflective access operation has occurred
> ------------------------------------------------------------------------------
>
> Key: WW-5101
> URL: https://issues.apache.org/jira/browse/WW-5101
> Project: Struts 2
> Issue Type: New Feature
> Components: Core
> Affects Versions: 2.5.26
> Reporter: Greg Huber
> Assignee: Greg Huber
> Priority: Minor
> Fix For: 2.6
>
> Time Spent: 1h
> Remaining Estimate: 0h
>
> Testing on java 11 AbstractLocalizedTextProvider outputs
> WARNING: An illegal reflective access operation has occurred
> WARNING: Illegal reflective access by
> com.opensymphony.xwork2.util.AbstractLocalizedTextProvider
> (file:struts2-core-2.5.26.jar|file:///struts2-core-2.5.26.jar) to field
> java.util.ResourceBundle.cacheList
> WARNING: Please consider reporting this to the maintainers of
> com.opensymphony.xwork2.util.AbstractLocalizedTextProvider
> WARNING: Use --illegal-access=warn to enable warnings of further illegal
> reflective access operations
> WARNING: All illegal access operations will be denied in a future release
> {code:java}
> clearMap(ResourceBundle.class, null, "cacheList");
> private void clearMap(Class cl, Object obj, String name) throws
> NoSuchFieldException, IllegalAccessException,
> NoSuchMethodException, InvocationTargetException{
> Field field = cl.getDeclaredField(name);
> field.setAccessible(true);
> Object cache = field.get(obj);
> synchronized (cache) {
> Class ccl = cache.getClass();
> Method clearMethod = ccl.getMethod("clear");
> clearMethod.invoke(cache);
> }
> }
> {code}
> When it executes the line field.setAccessible(true); produces the warning.
> Seems we might be able to replace
> {code:java}
> try{
> clearMap(ResourceBundle.class, null, "cacheList"); }
> catch (NoSuchFieldException e) {
> // happens in IBM JVM, that has a different ResourceBundle impl it has a
> 'cache' member
> clearMap(ResourceBundle.class, null, "cache");
> }{code}
> with
> {code:java}
> ResourceBundle.clearCache();
> {code}
> Tomcat also uses the same method to flush resourceEntries. Tomcat checks
> org.apache.catalina.loader.WebappClassLoader but for version #9 its using
> org.apache.catalina.loader.ParallelWebappClassLoader, so defaults to
> {code:java}
> clearMap(cl.getSuperclass(), loader, TOMCAT_RESOURCE_ENTRIES_FIELD);
> {code}
> Commenting out the tomcat reload, the Struts bundles seem to reload ok.
> Maybe drop this going forward?
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)