kinman      2002/09/05 10:28:13

  Modified:    jsr152/src/share/javax/servlet/jsp/tagext TagAdapter.java
  Log:
  - Patch by Jan Luehe
  
    Fix getParent(), to avoid IllegalArgumentException when wrapping null
    parent in TagAdapter.
  
  Revision  Changes    Path
  1.4       +22 -16    
jakarta-servletapi-5/jsr152/src/share/javax/servlet/jsp/tagext/TagAdapter.java
  
  Index: TagAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-servletapi-5/jsr152/src/share/javax/servlet/jsp/tagext/TagAdapter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TagAdapter.java   21 Aug 2002 22:05:34 -0000      1.3
  +++ TagAdapter.java   5 Sep 2002 17:28:13 -0000       1.4
  @@ -79,8 +79,11 @@
       private SimpleTag simpleTagAdaptee;
   
       /** The parent, of this tag, converted (if necessary) to be of type Tag */
  -    private Tag cachedParent;
  -    
  +    private Tag parent;
  +
  +    // Flag indicating whether we have already determined the parent
  +    private boolean parentDetermined;
  +
       /**
        * Creates a new TagAdapter that wraps the given SimpleTag and 
        * returns the parent tag when getParent() is called.
  @@ -121,26 +124,30 @@
   
   
       /**
  -     * Returns the value passed to setParent().  
  -     * This will either be the enclosing Tag (if parent implements Tag),
  -     * or an adapter to the enclosing Tag (if parent does
  -     * not implement Tag).
  +     * Returns the parent of this tag, which is always
  +     * getAdaptee().getParent().  
  +     *
  +     * This will either be the enclosing Tag (if getAdaptee().getParent()
  +     * implements Tag), or an adapter to the enclosing Tag (if 
  +     * getAdaptee().getParent() does not implement Tag).
        *
        * @return The parent of the tag being adapted.
        */
       public Tag getParent() {
  -     if( this.cachedParent == null ) {
  -         JspTag parent = simpleTagAdaptee.getParent();
  -         if( parent instanceof Tag ) {
  -             this.cachedParent = (Tag)parent;
  -         }
  -         else {
  -                // Must be SimpleTag - no other types defined.
  -             this.cachedParent = new TagAdapter( (SimpleTag)parent );
  +     if (!parentDetermined) {
  +         JspTag adapteeParent = simpleTagAdaptee.getParent();
  +         if (adapteeParent != null) {
  +             if (adapteeParent instanceof Tag) {
  +                 this.parent = (Tag) adapteeParent;
  +             } else {
  +                 // Must be SimpleTag - no other types defined.
  +                 this.parent = new TagAdapter((SimpleTag) adapteeParent);
  +             }
            }
  +         parentDetermined = true;
        }
   
  -     return this.cachedParent;
  +     return this.parent;
       }
       
       /**
  @@ -187,5 +194,4 @@
           throw new UnsupportedOperationException( 
               "Illegal to invoke release() on TagAdapter wrapper" );
       }
  -
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to