Author: markt
Date: Sat Nov 17 14:53:03 2012
New Revision: 1410732
URL: http://svn.apache.org/viewvc?rev=1410732&view=rev
Log:
Fix a FindBugs issue (incorrect synchronization)
Modified:
tomcat/trunk/java/org/apache/tomcat/util/modeler/NotificationInfo.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/modeler/NotificationInfo.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/modeler/NotificationInfo.java?rev=1410732&r1=1410731&r2=1410732&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/modeler/NotificationInfo.java
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/modeler/NotificationInfo.java Sat
Nov 17 14:53:03 2012
@@ -14,14 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.tomcat.util.modeler;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.management.MBeanNotificationInfo;
-
/**
* <p>Internal configuration information for a <code>Notification</code>
* descriptor.</p>
@@ -29,8 +29,8 @@ import javax.management.MBeanNotificatio
* @author Craig R. McClanahan
* @version $Id$
*/
-
public class NotificationInfo extends FeatureInfo {
+
static final long serialVersionUID = -6319885418912650856L;
// ----------------------------------------------------- Instance Variables
@@ -42,6 +42,7 @@ public class NotificationInfo extends Fe
*/
transient MBeanNotificationInfo info = null;
protected String notifTypes[] = new String[0];
+ protected ReadWriteLock notifTypesLock = new ReentrantReadWriteLock();
// ------------------------------------------------------------- Properties
@@ -74,7 +75,13 @@ public class NotificationInfo extends Fe
* The set of notification types for this MBean.
*/
public String[] getNotifTypes() {
- return (this.notifTypes);
+ Lock readLock = notifTypesLock.readLock();
+ try {
+ readLock.lock();
+ return this.notifTypes;
+ } finally {
+ readLock.unlock();
+ }
}
@@ -88,14 +95,18 @@ public class NotificationInfo extends Fe
*/
public void addNotifType(String notifType) {
- synchronized (notifTypes) {
+ Lock writeLock = notifTypesLock.writeLock();
+ try {
+ writeLock.lock();
+
String results[] = new String[notifTypes.length + 1];
System.arraycopy(notifTypes, 0, results, 0, notifTypes.length);
results[notifTypes.length] = notifType;
notifTypes = results;
this.info = null;
+ } finally {
+ writeLock.unlock();
}
-
}
@@ -107,7 +118,7 @@ public class NotificationInfo extends Fe
// Return our cached information (if any)
if (info != null)
- return (info);
+ return info;
// Create and return a new information object
info = new MBeanNotificationInfo
@@ -115,7 +126,7 @@ public class NotificationInfo extends Fe
//Descriptor descriptor = info.getDescriptor();
//addFields(descriptor);
//info.setDescriptor(descriptor);
- return (info);
+ return info;
}
@@ -132,11 +143,14 @@ public class NotificationInfo extends Fe
sb.append(", description=");
sb.append(description);
sb.append(", notifTypes=");
- sb.append(notifTypes.length);
+ Lock readLock = notifTypesLock.readLock();
+ try {
+ readLock.lock();
+ sb.append(notifTypes.length);
+ } finally {
+ readLock.unlock();
+ }
sb.append("]");
return (sb.toString());
-
}
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]