You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2006/03/26 00:05:57 UTC

svn commit: r388853 - in /xerces/java/trunk/src/org/apache/xerces/impl: dv/xs/ xs/

Author: mrglavas
Date: Sat Mar 25 15:05:56 2006
New Revision: 388853

URL: http://svn.apache.org/viewcvs?rev=388853&view=rev
Log:
Fixing JIRA Issue #1149:
http://issues.apache.org/jira/browse/XERCESJ-1149

The enhancements made to the annotation support in Xerces 2.8.0 made
it possible for NPEs to be thrown from the various XSObjects when a 
component has no annotations. In all getAnnotation() methods we now 
check if the list is null before accessing it.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeUseImpl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSElementDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSGroupDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelGroupImpl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSNotationDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSParticleDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XSWildcardDecl.java

Modified: xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java Sat Mar 25 15:05:56 2006
@@ -3088,25 +3088,27 @@
         fAnonymous = anon;
     }
 	
-	private static final class XSFacetImpl implements XSFacet {
-		final short kind;
-		final String value;
-		final boolean fixed;
-        XSObjectList annotations = null;  
-		
-		public XSFacetImpl(short kind, String value, boolean fixed, XSAnnotation annotation) {
-			this.kind = kind;
-			this.value = value;
-			this.fixed = fixed;
-
-		    if (annotation != null) {
+    private static final class XSFacetImpl implements XSFacet {
+        final short kind;
+        final String value;
+        final boolean fixed;
+        final XSObjectList annotations;  
+        
+        public XSFacetImpl(short kind, String value, boolean fixed, XSAnnotation annotation) {
+            this.kind = kind;
+            this.value = value;
+            this.fixed = fixed;
+            
+            if (annotation != null) {
                 this.annotations = new XSObjectListImpl();
                 ((XSObjectListImpl)this.annotations).add(annotation);
-            } else {
+            } 
+            else {
                 this.annotations =  XSObjectListImpl.EMPTY_LIST;
             }
-		}
-		/*
+        }
+        
+        /*
          * (non-Javadoc)
          * 
          * @see org.apache.xerces.xs.XSFacet#getAnnotation()
@@ -3117,7 +3119,7 @@
         public XSAnnotation getAnnotation() {
             return (XSAnnotation) annotations.item(0);
         }
-
+        
         /*
          * (non-Javadoc)
          * 
@@ -3129,122 +3131,120 @@
         public XSObjectList getAnnotations() {
             return annotations;
         }
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSFacet#getFacetKind()
-		 */
-		public short getFacetKind() {
-			return kind;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSFacet#getLexicalFacetValue()
-		 */
-		public String getLexicalFacetValue() {
-			return value;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSFacet#isFixed()
-		 */
-		public boolean getFixed() {
-			return fixed;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSObject#getName()
-		 */
-		public String getName() {
-			return null;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSObject#getNamespace()
-		 */
-		public String getNamespace() {
-			return null;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
-		 */
-		public XSNamespaceItem getNamespaceItem() {
-			// REVISIT: implement
-			return null;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSObject#getType()
-		 */
-		public short getType() {
-			return XSConstants.FACET;
-		}
-		
-	}
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSFacet#getFacetKind()
+         */
+        public short getFacetKind() {
+            return kind;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSFacet#getLexicalFacetValue()
+         */
+        public String getLexicalFacetValue() {
+            return value;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSFacet#isFixed()
+         */
+        public boolean getFixed() {
+            return fixed;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSObject#getName()
+         */
+        public String getName() {
+            return null;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSObject#getNamespace()
+         */
+        public String getNamespace() {
+            return null;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
+         */
+        public XSNamespaceItem getNamespaceItem() {
+            // REVISIT: implement
+            return null;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSObject#getType()
+         */
+        public short getType() {
+            return XSConstants.FACET;
+        }
+        
+    }
 	
-	private static final class XSMVFacetImpl implements XSMultiValueFacet {
-		final short kind;
-		XSObjectList annotations;
-		StringList values;
-		
-		public XSMVFacetImpl(short kind, StringList values, XSObjectList annotations) {
-			this.kind = kind;
-			this.values = values;
-			this.annotations = annotations;
-		}
-		
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSFacet#getFacetKind()
-		 */
-		public short getFacetKind() {
-			return kind;
-		}
-		
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSMultiValueFacet#getAnnotations()
-		 */
-		public XSObjectList getAnnotations() {
-			return annotations;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSMultiValueFacet#getLexicalFacetValues()
-		 */
-		public StringList getLexicalFacetValues() {
-			return values;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSObject#getName()
-		 */
-		public String getName() {
-			return null;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSObject#getNamespace()
-		 */
-		public String getNamespace() {
-			return null;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
-		 */
-		public XSNamespaceItem getNamespaceItem() {
-			// REVISIT: implement
-			return null;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.apache.xerces.xs.XSObject#getType()
-		 */
-		public short getType() {
-			return XSConstants.MULTIVALUE_FACET;
-		}
-	}
+    private static final class XSMVFacetImpl implements XSMultiValueFacet {
+        final short kind;
+        final XSObjectList annotations;
+        final StringList values;
+        
+        public XSMVFacetImpl(short kind, StringList values, XSObjectList annotations) {
+            this.kind = kind;
+            this.values = values;
+            this.annotations = (annotations != null) ? annotations : XSObjectListImpl.EMPTY_LIST;
+        }		
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSFacet#getFacetKind()
+         */
+        public short getFacetKind() {
+            return kind;
+        }	
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSMultiValueFacet#getAnnotations()
+         */
+        public XSObjectList getAnnotations() {
+            return annotations;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSMultiValueFacet#getLexicalFacetValues()
+         */
+        public StringList getLexicalFacetValues() {
+            return values;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSObject#getName()
+         */
+        public String getName() {
+            return null;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSObject#getNamespace()
+         */
+        public String getNamespace() {
+            return null;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
+         */
+        public XSNamespaceItem getNamespaceItem() {
+            // REVISIT: implement
+            return null;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.xerces.xs.XSObject#getType()
+         */
+        public short getType() {
+            return XSConstants.MULTIVALUE_FACET;
+        }
+    }
 
     public String getTypeNamespace() {
         return getNamespace();

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeDecl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeDecl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeDecl.java Sat Mar 25 15:05:56 2006
@@ -19,6 +19,7 @@
 import org.apache.xerces.impl.dv.XSSimpleType;
 import org.apache.xerces.xs.*;
 import org.apache.xerces.impl.dv.ValidatedInfo;
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 
 /**
  * The XML representation for an attribute declaration
@@ -151,14 +152,14 @@
      * Optional. Annotation.
      */
     public XSAnnotation getAnnotation() {
-        return (XSAnnotation) fAnnotations.item(0);
+        return (fAnnotations != null) ? (XSAnnotation) fAnnotations.item(0) : null;
     }
 
     /**
      * Optional. Annotations.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
     
     public ValidatedInfo getValInfo() {

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeGroupDecl.java Sat Mar 25 15:05:56 2006
@@ -346,14 +346,14 @@
      * Optional. Annotation.
      */
     public XSAnnotation getAnnotation() {
-        return (XSAnnotation) fAnnotations.item(0);
+        return (fAnnotations != null) ? (XSAnnotation) fAnnotations.item(0) : null;
     }
 
     /**
      * Optional. Annotations.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
     
 	/**

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeUseImpl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeUseImpl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeUseImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSAttributeUseImpl.java Sat Mar 25 15:05:56 2006
@@ -17,6 +17,7 @@
 package org.apache.xerces.impl.xs;
 
 import org.apache.xerces.impl.dv.ValidatedInfo;
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 import org.apache.xerces.xs.ShortList;
 import org.apache.xerces.xs.XSAttributeDeclaration;
 import org.apache.xerces.xs.XSAttributeUse;
@@ -43,7 +44,6 @@
     public short fConstraintType = XSConstants.VC_NONE;
     // value constraint value
     public ValidatedInfo fDefault = null;
-
     // optional annotation
     public XSObjectList fAnnotations = null;
     
@@ -143,7 +143,7 @@
      * Optional. Annotations.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
     
 } // class XSAttributeUseImpl

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java Sat Mar 25 15:05:56 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -666,7 +666,7 @@
      * Optional. Annotation.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
     
 	/**

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSElementDecl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSElementDecl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSElementDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSElementDecl.java Sat Mar 25 15:05:56 2006
@@ -28,6 +28,7 @@
 import org.apache.xerces.xs.XSObjectList;
 import org.apache.xerces.xs.XSTypeDefinition;
 import org.apache.xerces.impl.xs.util.XSNamedMapImpl;
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 
 /**
  * The XML representation for an element declaration
@@ -334,14 +335,14 @@
      * Optional. Annotation.
      */
     public XSAnnotation getAnnotation() {
-        return (XSAnnotation)fAnnotations.item(0);
+        return (fAnnotations != null) ? (XSAnnotation) fAnnotations.item(0) : null;
     }
 
     /**
      * Optional. Annotations.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
     
 

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSGroupDecl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSGroupDecl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSGroupDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSGroupDecl.java Sat Mar 25 15:05:56 2006
@@ -16,6 +16,7 @@
 
 package org.apache.xerces.impl.xs;
 
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 import org.apache.xerces.xs.*;
 
 /**
@@ -73,14 +74,14 @@
      * Optional. Annotation.
      */
     public XSAnnotation getAnnotation() {
-        return (XSAnnotation)fAnnotations.item(0);
+        return (fAnnotations != null) ? (XSAnnotation) fAnnotations.item(0) : null;
     }
 
     /**
      * Optional. Annotations.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
     
 	/**

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelGroupImpl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelGroupImpl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelGroupImpl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSModelGroupImpl.java Sat Mar 25 15:05:56 2006
@@ -218,14 +218,14 @@
      * Optional. Annotation.
      */
     public XSAnnotation getAnnotation() {
-        return (XSAnnotation) fAnnotations.item(0);
+        return (fAnnotations != null) ? (XSAnnotation) fAnnotations.item(0) : null;
     }
 
     /**
      * Optional. Annotations.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
 
     /**

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSNotationDecl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSNotationDecl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSNotationDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSNotationDecl.java Sat Mar 25 15:05:56 2006
@@ -16,6 +16,7 @@
 
 package org.apache.xerces.impl.xs;
 
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 import org.apache.xerces.xs.XSAnnotation;
 import org.apache.xerces.xs.XSConstants;
 import org.apache.xerces.xs.XSNamespaceItem;
@@ -88,14 +89,14 @@
      * Optional. Annotation.
      */
     public XSAnnotation getAnnotation() {
-        return (XSAnnotation) fAnnotations.item(0);
+        return (fAnnotations != null) ? (XSAnnotation) fAnnotations.item(0) : null;
     }
 
     /**
      * Optional. Annotations.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
 
 	/**

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSParticleDecl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSParticleDecl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSParticleDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSParticleDecl.java Sat Mar 25 15:05:56 2006
@@ -16,6 +16,7 @@
 
 package org.apache.xerces.impl.xs;
 
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 import org.apache.xerces.xs.XSConstants;
 import org.apache.xerces.xs.XSNamespaceItem;
 import org.apache.xerces.xs.XSObjectList;
@@ -237,7 +238,7 @@
      * Optional. Annotations.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
 
-} // class XSParticle
+} // class XSParticleDecl

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XSWildcardDecl.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/src/org/apache/xerces/impl/xs/XSWildcardDecl.java?rev=388853&r1=388852&r2=388853&view=diff
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XSWildcardDecl.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XSWildcardDecl.java Sat Mar 25 15:05:56 2006
@@ -23,6 +23,7 @@
 import org.apache.xerces.xs.XSObjectList;
 import org.apache.xerces.xs.XSWildcard;
 import org.apache.xerces.impl.xs.util.StringListImpl;
+import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 
 /**
  * The XML representation for a wildcard declaration
@@ -574,14 +575,14 @@
      * Optional. Annotation.
      */
     public XSAnnotation getAnnotation() {
-        return (XSAnnotation) fAnnotations.item(0);
+        return (fAnnotations != null) ? (XSAnnotation) fAnnotations.item(0) : null;
     }
 
     /**
      * Optional. Annotations.
      */
     public XSObjectList getAnnotations() {
-        return fAnnotations;
+        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
     }
 
 	/**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org