[seam-commits] Seam SVN: r9716 - trunk/src/main/org/jboss/seam/security.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Dec 4 03:06:28 EST 2008


Author: dan.j.allen
Date: 2008-12-04 03:06:28 -0500 (Thu, 04 Dec 2008)
New Revision: 9716

Modified:
   trunk/src/main/org/jboss/seam/security/SecurityInterceptor.java
Log:
workaround a JVM bug by initializing the restrictions map lazily if it is found to be null; use the volatile keyword for thread safety

Modified: trunk/src/main/org/jboss/seam/security/SecurityInterceptor.java
===================================================================
--- trunk/src/main/org/jboss/seam/security/SecurityInterceptor.java	2008-12-04 08:00:42 UTC (rev 9715)
+++ trunk/src/main/org/jboss/seam/security/SecurityInterceptor.java	2008-12-04 08:06:28 UTC (rev 9716)
@@ -30,7 +30,11 @@
 {
    private static final long serialVersionUID = -6567750187000766925L;
    
-   private transient Map<Method,Restriction> restrictions = new HashMap<Method,Restriction>();
+   /**
+    * You may encounter a JVM bug where the field initializer is not evaluated for a transient field after deserialization.
+    * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6252102
+    */
+   private transient volatile Map<Method,Restriction> restrictions = new HashMap<Method,Restriction>();
    
    private class Restriction
    {
@@ -159,10 +163,20 @@
 
    private Restriction getRestriction(Method interfaceMethod) throws Exception
    {
+      // see field declaration as to why this is done
+      if (restrictions == null)
+      {
+         synchronized(this)
+         {
+            restrictions = new HashMap<Method, Restriction>();
+         }
+      }
+      
       if (!restrictions.containsKey(interfaceMethod))
       {
          synchronized(restrictions)
          {
+            // FIXME this logic should be abstracted rather than sitting in the middle of this interceptor
             if (!restrictions.containsKey(interfaceMethod))
             {  
                Restriction restriction = null;




More information about the seam-commits mailing list