Author: mrglavas
Date: Wed May 27 13:42:53 2009
New Revision: 779172

URL: http://svn.apache.org/viewvc?rev=779172&view=rev
Log:
Fixing JIRA Issue #1374: http://issues.apache.org/jira/browse/XERCESJ-1374. 
Fixing potential NPEs when comparing namespace URIs in the Schema DOM. Patch 
thanks to Arthur De Magalhaes.

Modified:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/ElementImpl.java

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/ElementImpl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/ElementImpl.java?rev=779172&r1=779171&r2=779172&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/ElementImpl.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/opti/ElementImpl.java
 Wed May 27 13:42:53 2009
@@ -186,7 +186,7 @@
     
     public String getAttributeNS(String namespaceURI, String localName) {
         for (int i=0; i<attrs.length; i++) {
-            if (attrs[i].getLocalName().equals(localName) && 
attrs[i].getNamespaceURI().equals(namespaceURI)) {
+            if (attrs[i].getLocalName().equals(localName) && 
nsEquals(attrs[i].getNamespaceURI(), namespaceURI)) {
                 return attrs[i].getValue();
             }
         }
@@ -196,7 +196,7 @@
     
     public Attr getAttributeNodeNS(String namespaceURI, String localName) {
         for (int i=0; i<attrs.length; i++) {
-            if (attrs[i].getName().equals(localName) && 
attrs[i].getNamespaceURI().equals(namespaceURI)) {
+            if (attrs[i].getName().equals(localName) && 
nsEquals(attrs[i].getNamespaceURI(), namespaceURI)) {
                 return attrs[i];
             }
         }
@@ -216,7 +216,7 @@
     
     public boolean hasAttributeNS(String namespaceURI, String localName) {
         for (int i=0; i<attrs.length; i++) {
-            if (attrs[i].getName().equals(localName) && 
attrs[i].getNamespaceURI().equals(namespaceURI)) {
+            if (attrs[i].getName().equals(localName) && 
nsEquals(attrs[i].getNamespaceURI(), namespaceURI)) {
                 return true;
             }
         }
@@ -255,4 +255,17 @@
     public String getSyntheticAnnotation() {
         return fSyntheticAnnotation;
     }
+    
+    /**
+     * Compares two namespace URIs with an extra case for null entries
+     */
+    private static boolean nsEquals(String nsURI_1, String nsURI_2) {
+        if (nsURI_1 == null) {
+            return (nsURI_2 == null);
+        }
+        else {
+            return nsURI_1.equals(nsURI_2);
+        }
+    }
+    
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to