Patch: RFC: SAX driver change

Tom Tromey tromey@redhat.com
Sat Feb 12 06:19:00 GMT 2005


Chris, can you take a look at this?

Jonas startup works ok(-ish) for Andrew, but fails for me.  The
difference is that he's using xalan and I'm using the XML code from
Classpath (aelfred/gnu jaxp/etc).

Anyway, while debugging I came across this... the javadoc for
org.xml.sax.Attributes says that getURI, getLocalName, and getQName
should return null if the index is out of range, but an empty string
in other situations.  We were returning null for getLocalName even
when the index was valid.

This patch lets jonas get a little further.  It still doesn't start
for me, and the new problem also seems sax-related, I'm sure you'll
hear more from me soon :-)

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* gnu/xml/aelfred2/SAXDriver.java (getURI): Check index.
	(getLocalName): Likewise.  Don't return null if index is valid.
	(getQName): Likewise.

Index: gnu/xml/aelfred2/SAXDriver.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/xml/aelfred2/SAXDriver.java,v
retrieving revision 1.1
diff -u -r1.1 SAXDriver.java
--- gnu/xml/aelfred2/SAXDriver.java 2 Feb 2005 00:42:07 -0000 1.1
+++ gnu/xml/aelfred2/SAXDriver.java 11 Feb 2005 22:32:33 -0000
@@ -1,5 +1,5 @@
 /* SAXDriver.java -- 
-   Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.
+   Copyright (C) 1999,2000,2001,2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -1051,6 +1051,8 @@
      */
     public String getURI (int index)
     {
+	if (index >= attributesList.size ())
+	  return null;
 	return ((Attribute) attributesList.get (index)).nameSpace;
     }
 
@@ -1059,6 +1061,8 @@
      */
     public String getLocalName (int index)
     {
+	if (index >= attributesList.size ())
+	  return null;
         Attribute attr = (Attribute) attributesList.get (index);
         // FIXME attr.localName is sometimes null, why?
         if (namespaces && attr.localName == null)
@@ -1068,7 +1072,7 @@
             attr.localName = (ci == -1) ? attr.name :
               attr.name.substring(ci + 1);
           }
-        return attr.localName;
+        return attr.localName == null ? "" : attr.localName;
     }
 
     /**
@@ -1076,7 +1080,10 @@
      */
     public String getQName (int i)
     {
-    	return ((Attribute) attributesList.get (i)).name;
+	if (i >= attributesList.size ())
+	  return null;
+    	String result = ((Attribute) attributesList.get (i)).name;
+	return result == null ? "" : result;
     }
 
     /**



More information about the Java-patches mailing list