You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by mi...@apache.org on 2003/11/06 19:33:55 UTC

cvs commit: jakarta-tapestry/framework/src/org/apache/tapestry/enhance DefaultComponentClassEnhancer.java

mindbridge    2003/11/06 10:33:55

  Modified:    framework/src/org/apache/tapestry/enhance
                        DefaultComponentClassEnhancer.java
  Log:
  Synchronizing the code enhancer to remove the race condition
  
  PR: 24425   race condition in class enhancement  by Michael.Frericks@sparkassen-informatik.de
  
  Revision  Changes    Path
  1.12      +31 -24    jakarta-tapestry/framework/src/org/apache/tapestry/enhance/DefaultComponentClassEnhancer.java
  
  Index: DefaultComponentClassEnhancer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/enhance/DefaultComponentClassEnhancer.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultComponentClassEnhancer.java	17 Oct 2003 18:53:53 -0000	1.11
  +++ DefaultComponentClassEnhancer.java	6 Nov 2003 18:33:55 -0000	1.12
  @@ -57,6 +57,7 @@
   
   import java.lang.reflect.Method;
   import java.lang.reflect.Modifier;
  +import java.util.Collections;
   import java.util.HashMap;
   import java.util.HashSet;
   import java.util.Map;
  @@ -89,16 +90,17 @@
        * 
        **/
   
  -    private Map _cachedClasses = new HashMap();
  +    private Map _cachedClasses;
       private IResourceResolver _resolver;
       private IEnhancedClassFactory _factory;
   
       public DefaultComponentClassEnhancer(IResourceResolver resolver)
       {
  +        _cachedClasses = Collections.synchronizedMap(new HashMap());
           _resolver = resolver;
           _factory = createEnhancedClassFactory();
       }
  -    
  +
       protected IEnhancedClassFactory createEnhancedClassFactory()
       {
           return new EnhancedClassFactory(getResourceResolver());
  @@ -121,21 +123,26 @@
   
           if (result == null)
           {
  -            result = constructComponentClass(specification, className);
  -            storeCachedClass(specification, result);
  +            synchronized (this)
  +            {
  +                result = getCachedClass(specification);
  +                if (result == null)
  +                {
  +                    result = constructComponentClass(specification, className);
  +                    storeCachedClass(specification, result);
  +                }
  +            }
           }
   
           return result;
       }
   
  -    protected synchronized void storeCachedClass(
  -        IComponentSpecification specification,
  -        Class cachedClass)
  +    protected void storeCachedClass(IComponentSpecification specification, Class cachedClass)
       {
           _cachedClasses.put(specification, cachedClass);
       }
   
  -    protected synchronized Class getCachedClass(IComponentSpecification specification)
  +    protected Class getCachedClass(IComponentSpecification specification)
       {
           return (Class) _cachedClasses.get(specification);
       }
  @@ -146,7 +153,9 @@
        * 
        **/
   
  -    protected Class constructComponentClass(IComponentSpecification specification, String className)
  +    protected Class constructComponentClass(
  +        IComponentSpecification specification,
  +        String className)
       {
           Class result = null;
   
  @@ -162,20 +171,18 @@
           try
           {
               ComponentClassFactory factory = createComponentClassFactory(specification, result);
  -            
  +
               if (factory.needsEnhancement())
               {
                   result = factory.createEnhancedSubclass();
  -            
  +
                   validateEnhancedClass(result, className, specification);
               }
           }
           catch (CodeGenerationException e)
           {
               throw new ApplicationRuntimeException(
  -                Tapestry.format(
  -                    "ComponentClassFactory.code-generation-error",
  -                    className),
  +                Tapestry.format("ComponentClassFactory.code-generation-error", className),
                   e);
           }
   
  @@ -220,7 +227,7 @@
   
           Set implementedMethods = new HashSet();
           Class current = subject;
  - 
  +
           while (true)
           {
               Method m = checkForAbstractMethods(current, implementedMethods);
  @@ -233,20 +240,20 @@
                       specification.getLocation(),
                       null);
   
  -			// An earlier version of this code walked the interfaces directly,
  -			// but it appears that implementing an interface actually
  -			// puts abstract method declarations into the class
  -			// (at least, in terms of what getDeclaredMethods() returns).
  +            // An earlier version of this code walked the interfaces directly,
  +            // but it appears that implementing an interface actually
  +            // puts abstract method declarations into the class
  +            // (at least, in terms of what getDeclaredMethods() returns).
   
               // March up to the super class.
   
               current = current.getSuperclass();
  -            
  +
               // Once advanced up to a concrete class, we trust that
               // the compiler did its checking.
  -            
  +
               if (!Modifier.isAbstract(current.getModifiers()))
  -            	break;
  +                break;
           }
   
       }
  @@ -275,7 +282,7 @@
   
               boolean isAbstract = Modifier.isAbstract(m.getModifiers());
   
  -			MethodSignature s = new MethodSignature(m);
  +            MethodSignature s = new MethodSignature(m);
   
               if (isAbstract)
               {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org