ASF Bugzilla – Attachment 23455 Details for
Bug 46990
Synchronize target can be changed midway
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Fix broken synchronization
BadSynch.patch (text/plain), 19.90 KB, created by
Sebb
on 2009-04-07 18:52:10 UTC
(
hide
)
Description:
Fix broken synchronization
Filename:
MIME Type:
Creator:
Sebb
Created:
2009-04-07 18:52:10 UTC
Size:
19.90 KB
patch
obsolete
>Index: java/org/apache/catalina/core/StandardContext.java >=================================================================== >--- java/org/apache/catalina/core/StandardContext.java (revision 762971) >+++ java/org/apache/catalina/core/StandardContext.java (working copy) >@@ -202,6 +202,8 @@ > * application, in the order they were encountered in the web.xml file. > */ > private String applicationListeners[] = new String[0]; >+ >+ private final Object applicationListenersLock = new Object(); > > > /** >@@ -224,6 +226,8 @@ > private ApplicationParameter applicationParameters[] = > new ApplicationParameter[0]; > >+ private final Object applicationParametersLock = new Object(); >+ > > /** > * The application available flag for this Context. >@@ -264,6 +268,8 @@ > * The security constraints for this web application. > */ > private SecurityConstraint constraints[] = new SecurityConstraint[0]; >+ >+ private final Object constraintsLock = new Object(); > > > /** >@@ -360,6 +366,8 @@ > * they were defined in the deployment descriptor. > */ > private FilterMap filterMaps[] = new FilterMap[0]; >+ >+ private final Object filterMapsLock = new Object(); > > > /** >@@ -374,6 +382,8 @@ > */ > private String instanceListeners[] = new String[0]; > >+ private final Object instanceListenersLock = new Object(); >+ > > /** > * The login configuration descriptor for this web application. >@@ -491,6 +501,8 @@ > */ > private String securityRoles[] = new String[0]; > >+ private final Object securityRolesLock = new Object(); >+ > > /** > * The servlet mappings for this web application, keyed by >@@ -498,6 +510,7 @@ > */ > private HashMap servletMappings = new HashMap(); > >+ private final Object servletMappingsLock = new Object(); > > /** > * The session timeout (in minutes) for this web application. >@@ -540,12 +553,16 @@ > */ > private String watchedResources[] = new String[0]; > >+ private final Object watchedResourcesLock = new Object(); >+ > > /** > * The welcome files for this application. > */ > private String welcomeFiles[] = new String[0]; > >+ private final Object welcomeFilesLock = new Object(); >+ > > /** > * The set of classnames of LifecycleListeners that will be added >@@ -553,6 +570,7 @@ > */ > private String wrapperLifecycles[] = new String[0]; > >+ private final Object wrapperLifecyclesLock = new Object(); > > /** > * The set of classnames of ContainerListeners that will be added >@@ -560,6 +578,7 @@ > */ > private String wrapperListeners[] = new String[0]; > >+ private final Object wrapperListenersLock = new Object(); > > /** > * The pathname to the work directory for this context (relative to >@@ -2000,7 +2019,7 @@ > */ > public void addApplicationListener(String listener) { > >- synchronized (applicationListeners) { >+ synchronized (applicationListenersLock) { > String results[] =new String[applicationListeners.length + 1]; > for (int i = 0; i < applicationListeners.length; i++) { > if (listener.equals(applicationListeners[i])) { >@@ -2027,7 +2046,7 @@ > */ > public void addApplicationParameter(ApplicationParameter parameter) { > >- synchronized (applicationParameters) { >+ synchronized (applicationParametersLock) { > String newName = parameter.getName(); > for (int i = 0; i < applicationParameters.length; i++) { > if (newName.equals(applicationParameters[i].getName()) && >@@ -2124,7 +2143,7 @@ > } > > // Add this constraint to the set for our web application >- synchronized (constraints) { >+ synchronized (constraintsLock) { > SecurityConstraint results[] = > new SecurityConstraint[constraints.length + 1]; > for (int i = 0; i < constraints.length; i++) >@@ -2240,7 +2259,7 @@ > } > > // Add this filter mapping to our registered set >- synchronized (filterMaps) { >+ synchronized (filterMapsLock) { > FilterMap results[] =new FilterMap[filterMaps.length + 1]; > System.arraycopy(filterMaps, 0, results, 0, filterMaps.length); > results[filterMaps.length] = filterMap; >@@ -2259,7 +2278,7 @@ > */ > public void addInstanceListener(String listener) { > >- synchronized (instanceListeners) { >+ synchronized (instanceListenersLock) { > String results[] =new String[instanceListeners.length + 1]; > for (int i = 0; i < instanceListeners.length; i++) > results[i] = instanceListeners[i]; >@@ -2402,7 +2421,7 @@ > */ > public void addSecurityRole(String role) { > >- synchronized (securityRoles) { >+ synchronized (securityRolesLock) { > String results[] =new String[securityRoles.length + 1]; > for (int i = 0; i < securityRoles.length; i++) > results[i] = securityRoles[i]; >@@ -2453,7 +2472,7 @@ > (sm.getString("standardContext.servletMap.pattern", pattern)); > > // Add this mapping to our registered set >- synchronized (servletMappings) { >+ synchronized (servletMappingsLock) { > String name2 = (String) servletMappings.get(pattern); > if (name2 != null) { > // Don't allow more than one servlet on the same pattern >@@ -2497,7 +2516,7 @@ > */ > public void addWatchedResource(String name) { > >- synchronized (watchedResources) { >+ synchronized (watchedResourcesLock) { > String results[] = new String[watchedResources.length + 1]; > for (int i = 0; i < watchedResources.length; i++) > results[i] = watchedResources[i]; >@@ -2516,7 +2535,7 @@ > */ > public void addWelcomeFile(String name) { > >- synchronized (welcomeFiles) { >+ synchronized (welcomeFilesLock) { > // Welcome files from the application deployment descriptor > // completely replace those from the default conf/web.xml file > if (replaceWelcomeFiles) { >@@ -2543,7 +2562,7 @@ > */ > public void addWrapperLifecycle(String listener) { > >- synchronized (wrapperLifecycles) { >+ synchronized (wrapperLifecyclesLock) { > String results[] =new String[wrapperLifecycles.length + 1]; > for (int i = 0; i < wrapperLifecycles.length; i++) > results[i] = wrapperLifecycles[i]; >@@ -2563,7 +2582,7 @@ > */ > public void addWrapperListener(String listener) { > >- synchronized (wrapperListeners) { >+ synchronized (wrapperListenersLock) { > String results[] =new String[wrapperListeners.length + 1]; > for (int i = 0; i < wrapperListeners.length; i++) > results[i] = wrapperListeners[i]; >@@ -2595,7 +2614,7 @@ > wrapper = new StandardWrapper(); > } > >- synchronized (instanceListeners) { >+ synchronized (instanceListenersLock) { > for (int i = 0; i < instanceListeners.length; i++) { > try { > Class clazz = Class.forName(instanceListeners[i]); >@@ -2609,7 +2628,7 @@ > } > } > >- synchronized (wrapperLifecycles) { >+ synchronized (wrapperLifecyclesLock) { > for (int i = 0; i < wrapperLifecycles.length; i++) { > try { > Class clazz = Class.forName(wrapperLifecycles[i]); >@@ -2624,7 +2643,7 @@ > } > } > >- synchronized (wrapperListeners) { >+ synchronized (wrapperListenersLock) { > for (int i = 0; i < wrapperListeners.length; i++) { > try { > Class clazz = Class.forName(wrapperListeners[i]); >@@ -2659,7 +2678,9 @@ > */ > public ApplicationParameter[] findApplicationParameters() { > >- return (applicationParameters); >+ synchronized (applicationParametersLock) { >+ return (applicationParameters); >+ } > > } > >@@ -2777,7 +2798,9 @@ > */ > public String[] findInstanceListeners() { > >- return (instanceListeners); >+ synchronized (instanceListenersLock) { >+ return (instanceListeners); >+ } > > } > >@@ -2936,7 +2959,7 @@ > */ > public boolean findSecurityRole(String role) { > >- synchronized (securityRoles) { >+ synchronized (securityRolesLock) { > for (int i = 0; i < securityRoles.length; i++) { > if (role.equals(securityRoles[i])) > return (true); >@@ -2953,7 +2976,9 @@ > */ > public String[] findSecurityRoles() { > >- return (securityRoles); >+ synchronized (securityRolesLock) { >+ return (securityRoles); >+ } > > } > >@@ -2966,7 +2991,7 @@ > */ > public String findServletMapping(String pattern) { > >- synchronized (servletMappings) { >+ synchronized (servletMappingsLock) { > return ((String) servletMappings.get(pattern)); > } > >@@ -2979,7 +3004,7 @@ > */ > public String[] findServletMappings() { > >- synchronized (servletMappings) { >+ synchronized (servletMappingsLock) { > String results[] = new String[servletMappings.size()]; > return > ((String[]) servletMappings.keySet().toArray(results)); >@@ -3062,7 +3087,7 @@ > */ > public boolean findWelcomeFile(String name) { > >- synchronized (welcomeFiles) { >+ synchronized (welcomeFilesLock) { > for (int i = 0; i < welcomeFiles.length; i++) { > if (name.equals(welcomeFiles[i])) > return (true); >@@ -3078,7 +3103,9 @@ > * defined, a zero length array will be returned. > */ > public String[] findWatchedResources() { >- return watchedResources; >+ synchronized (watchedResourcesLock) { >+ return watchedResources; >+ } > } > > >@@ -3088,7 +3115,9 @@ > */ > public String[] findWelcomeFiles() { > >- return (welcomeFiles); >+ synchronized (welcomeFilesLock) { >+ return (welcomeFiles); >+ } > > } > >@@ -3099,7 +3128,9 @@ > */ > public String[] findWrapperLifecycles() { > >- return (wrapperLifecycles); >+ synchronized (wrapperLifecyclesLock) { >+ return (wrapperLifecycles); >+ } > > } > >@@ -3110,7 +3141,9 @@ > */ > public String[] findWrapperListeners() { > >- return (wrapperListeners); >+ synchronized (wrapperListenersLock) { >+ return (wrapperListeners); >+ } > > } > >@@ -3169,7 +3202,7 @@ > */ > public void removeApplicationListener(String listener) { > >- synchronized (applicationListeners) { >+ synchronized (applicationListenersLock) { > > // Make sure this welcome file is currently present > int n = -1; >@@ -3209,7 +3242,7 @@ > */ > public void removeApplicationParameter(String name) { > >- synchronized (applicationParameters) { >+ synchronized (applicationParametersLock) { > > // Make sure this parameter is currently present > int n = -1; >@@ -3268,7 +3301,7 @@ > */ > public void removeConstraint(SecurityConstraint constraint) { > >- synchronized (constraints) { >+ synchronized (constraintsLock) { > > // Make sure this constraint is currently present > int n = -1; >@@ -3348,7 +3381,7 @@ > */ > public void removeFilterMap(FilterMap filterMap) { > >- synchronized (filterMaps) { >+ synchronized (filterMapsLock) { > > // Make sure this filter mapping is currently present > int n = -1; >@@ -3384,7 +3417,7 @@ > */ > public void removeInstanceListener(String listener) { > >- synchronized (instanceListeners) { >+ synchronized (instanceListenersLock) { > > // Make sure this welcome file is currently present > int n = -1; >@@ -3496,7 +3529,7 @@ > */ > public void removeSecurityRole(String role) { > >- synchronized (securityRoles) { >+ synchronized (securityRolesLock) { > > // Make sure this security role is currently present > int n = -1; >@@ -3535,7 +3568,7 @@ > public void removeServletMapping(String pattern) { > > String name = null; >- synchronized (servletMappings) { >+ synchronized (servletMappingsLock) { > name = (String) servletMappings.remove(pattern); > } > Wrapper wrapper = (Wrapper) findChild(name); >@@ -3570,7 +3603,7 @@ > */ > public void removeWatchedResource(String name) { > >- synchronized (watchedResources) { >+ synchronized (watchedResourcesLock) { > > // Make sure this watched resource is currently present > int n = -1; >@@ -3607,7 +3640,7 @@ > */ > public void removeWelcomeFile(String name) { > >- synchronized (welcomeFiles) { >+ synchronized (welcomeFilesLock) { > > // Make sure this welcome file is currently present > int n = -1; >@@ -3647,7 +3680,7 @@ > public void removeWrapperLifecycle(String listener) { > > >- synchronized (wrapperLifecycles) { >+ synchronized (wrapperLifecyclesLock) { > > // Make sure this welcome file is currently present > int n = -1; >@@ -3686,7 +3719,7 @@ > public void removeWrapperListener(String listener) { > > >- synchronized (wrapperListeners) { >+ synchronized (wrapperListenersLock) { > > // Make sure this welcome file is currently present > int n = -1; >@@ -4633,7 +4666,9 @@ > // Notify our interested LifecycleListeners > lifecycle.fireLifecycleEvent(DESTROY_EVENT, null); > >- instanceListeners = new String[0]; >+ synchronized (instanceListenersLock) { >+ instanceListeners = new String[0]; >+ } > > } > >Index: java/org/apache/catalina/core/StandardHost.java >=================================================================== >--- java/org/apache/catalina/core/StandardHost.java (revision 762971) >+++ java/org/apache/catalina/core/StandardHost.java (working copy) >@@ -72,6 +72,8 @@ > * The set of aliases for this Host. > */ > private String[] aliases = new String[0]; >+ >+ private final Object aliasesLock = new Object(); > > > /** >@@ -491,20 +493,19 @@ > > alias = alias.toLowerCase(); > >- // Skip duplicate aliases >- for (int i = 0; i < aliases.length; i++) { >- if (aliases[i].equals(alias)) >- return; >+ synchronized (aliasesLock) { >+ // Skip duplicate aliases >+ for (int i = 0; i < aliases.length; i++) { >+ if (aliases[i].equals(alias)) >+ return; >+ } >+ // Add this alias to the list >+ String newAliases[] = new String[aliases.length + 1]; >+ for (int i = 0; i < aliases.length; i++) >+ newAliases[i] = aliases[i]; >+ newAliases[aliases.length] = alias; >+ aliases = newAliases; > } >- >- // Add this alias to the list >- String newAliases[] = new String[aliases.length + 1]; >- for (int i = 0; i < aliases.length; i++) >- newAliases[i] = aliases[i]; >- newAliases[aliases.length] = alias; >- >- aliases = newAliases; >- > // Inform interested listeners > fireContainerEvent(ADD_ALIAS_EVENT, alias); > >@@ -533,7 +534,9 @@ > */ > public String[] findAliases() { > >- return (this.aliases); >+ synchronized (aliasesLock) { >+ return (this.aliases); >+ } > > } > >@@ -608,7 +611,7 @@ > > alias = alias.toLowerCase(); > >- synchronized (aliases) { >+ synchronized (aliasesLock) { > > // Make sure this alias is currently present > int n = -1; >@@ -743,7 +746,9 @@ > } > > public String[] getAliases() { >- return aliases; >+ synchronized (aliasesLock) { >+ return aliases; >+ } > } > > private boolean initialized=false; >Index: java/org/apache/catalina/tribes/membership/Membership.java >=================================================================== >--- java/org/apache/catalina/tribes/membership/Membership.java (revision 762971) >+++ java/org/apache/catalina/tribes/membership/Membership.java (working copy) >@@ -56,13 +56,15 @@ > */ > protected MemberImpl[] members = EMPTY_MEMBERS; > >+ private final Object membersLock = new Object(); >+ > /** > * sort members by alive time > */ > protected Comparator memberComparator = new MemberComparator(); > > public Object clone() { >- synchronized (members) { >+ synchronized (membersLock) { > Membership clone = new Membership(local, memberComparator); > clone.map = (HashMap) map.clone(); > clone.members = new MemberImpl[members.length]; >@@ -138,7 +140,7 @@ > * @param member The member to add > */ > public synchronized MbrEntry addMember(MemberImpl member) { >- synchronized (members) { >+ synchronized (membersLock) { > MbrEntry entry = new MbrEntry(member); > if (!map.containsKey(member) ) { > map.put(member, entry); >@@ -159,7 +161,7 @@ > */ > public void removeMember(MemberImpl member) { > map.remove(member); >- synchronized (members) { >+ synchronized (membersLock) { > int n = -1; > for (int i = 0; i < members.length; i++) { > if (members[i] == member || members[i].equals(member)) { >Index: java/org/apache/catalina/util/InstanceSupport.java >=================================================================== >--- java/org/apache/catalina/util/InstanceSupport.java (revision 762971) >+++ java/org/apache/catalina/util/InstanceSupport.java (working copy) >@@ -64,6 +64,8 @@ > * The set of registered InstanceListeners for event notifications. > */ > private InstanceListener listeners[] = new InstanceListener[0]; >+ >+ private final Object listenersLock = new Object(); // Lock object for changes to listeners > > > /** >@@ -95,7 +97,7 @@ > */ > public void addInstanceListener(InstanceListener listener) { > >- synchronized (listeners) { >+ synchronized (listenersLock) { > InstanceListener results[] = > new InstanceListener[listeners.length + 1]; > for (int i = 0; i < listeners.length; i++) >@@ -312,7 +314,7 @@ > */ > public void removeInstanceListener(InstanceListener listener) { > >- synchronized (listeners) { >+ synchronized (listenersLock) { > int n = -1; > for (int i = 0; i < listeners.length; i++) { > if (listeners[i] == listener) { >Index: java/org/apache/catalina/util/LifecycleSupport.java >=================================================================== >--- java/org/apache/catalina/util/LifecycleSupport.java (revision 762971) >+++ java/org/apache/catalina/util/LifecycleSupport.java (working copy) >@@ -66,6 +66,8 @@ > * The set of registered LifecycleListeners for event notifications. > */ > private LifecycleListener listeners[] = new LifecycleListener[0]; >+ >+ private final Object listenersLock = new Object(); // Lock object for changes to listeners > > > // --------------------------------------------------------- Public Methods >@@ -78,7 +80,7 @@ > */ > public void addLifecycleListener(LifecycleListener listener) { > >- synchronized (listeners) { >+ synchronized (listenersLock) { > LifecycleListener results[] = > new LifecycleListener[listeners.length + 1]; > for (int i = 0; i < listeners.length; i++) >@@ -126,7 +128,7 @@ > */ > public void removeLifecycleListener(LifecycleListener listener) { > >- synchronized (listeners) { >+ synchronized (listenersLock) { > int n = -1; > for (int i = 0; i < listeners.length; i++) { > if (listeners[i] == listener) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 46990
: 23455