You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2003/06/25 21:02:00 UTC
DO NOT REPLY [Bug 21091] New: -
RequestUtils.getModulePrefixes needs synchronization
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21091>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21091
RequestUtils.getModulePrefixes needs synchronization
Summary: RequestUtils.getModulePrefixes needs synchronization
Product: Struts
Version: 1.1RC2
Platform: Sun
OS/Version: Other
Status: NEW
Severity: Normal
Priority: Other
Component: Controller
AssignedTo: struts-dev@jakarta.apache.org
ReportedBy: jogoussard@hotmail.com
RequestUtils.getModulePrefixes can throw a ConcurrentModificationException if
accessed from several threads. The problem is that the code iterates over
the attributes names in the ServletContext and adds at the end a new
attribute. If 2 threads are executing this code, one will get the exception.
Modified fixed code:
public static String[] getModulePrefixes(ServletContext context) {
String prefixes[] = (String[]) context.getAttribute(PREFIXES_KEY);
if (prefixes != null) {
return (prefixes);
}
synchronized (this) {
if (prefixes != null) {
return (prefixes);
}
ArrayList list = new ArrayList();
Enumeration names = context.getAttributeNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (!name.startsWith(Globals.MODULE_KEY)) {
continue;
}
String prefix = name.substring(Globals.MODULE_KEY.length());
if (prefix.length() > 0) {
list.add(prefix);
}
}
prefixes = (String[]) list.toArray(new String[list.size()]);
context.setAttribute(PREFIXES_KEY, prefixes);
}
return (prefixes);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org