[jdom-interest] StringIndexOutOfBoundsException in SaxHandler
S. Seide
ml-jdom at seide.st
Tue Jul 28 09:54:40 PDT 2009
Hello,
using jdom 1.1.1 on android 1.5 gives an
StringIndexOutOfBoundsException. Androids default XML-Parser ExPat
returns for Attributes without namespace an emtpy qname:
<?xml version="1.0" encoding="UTF-8"?>
<config version="2009-07-23" summary="main AVF configuration file">
</config>
atts.getLocalName(i) - "version"
atts.getQName(i) - ""
This seems to be the expected behavior, since
http://www.saxproject.org/apidoc/org/xml/sax/Attributes.html#getQName(int)
says getQName returns an empty string if no qualified name is available:
getQName
public java.lang.String getQName(int index)
Look up an attribute's XML qualified (prefixed) name by index.
Parameters:
index - The attribute index (zero-based).
Returns:
The XML qualified name, or the empty string if none is available, or
null if the index is out of range.
StackTrace:
> 07-28 14:54:10.354: ERROR/Global(725): java.lang.StringIndexOutOfBoundsException
> 07-28 14:54:10.354: ERROR/Global(725): at java.lang.String.substring(String.java:1571)
> 07-28 14:54:10.354: ERROR/Global(725): at org.jdom.input.SAXHandler.startElement(SAXHandler.java:568)
> 07-28 14:54:10.354: ERROR/Global(725): at org.apache.harmony.xml.ExpatParser.startElement(ExpatParser.java:145)
> 07-28 14:54:10.354: ERROR/Global(725): at org.apache.harmony.xml.ExpatParser.append(Native Method)
> 07-28 14:54:10.354: ERROR/Global(725): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:506)
> 07-28 14:54:10.354: ERROR/Global(725): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
> 07-28 14:54:10.354: ERROR/Global(725): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
> 07-28 14:54:10.354: ERROR/Global(725): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)
> 07-28 14:54:10.354: ERROR/Global(725): at org.jdom.input.SAXBuilder.build(SAXBuilder.java:518)
> 07-28 14:54:10.354: ERROR/Global(725): at org.jdom.input.SAXBuilder.build(SAXBuilder.java:865)
> 07-28 14:54:10.354: ERROR/Global(725): at com.tlabs.avf.AVFGlobal.addInputStreams(AVFGlobal.java:538)
> 07-28 14:54:10.354: ERROR/Global(725): at com.tlabs.avf.AVFGlobal.initialize(AVFGlobal.java:630)
> 07-28 14:54:10.354: ERROR/Global(725): at com.tlabs.avf.AVFMain.init(AVFMain.java:122)
> 07-28 14:54:10.354: ERROR/Global(725): at com.tlabs.avf.test.AVFMainTest.onCreate(AVFMainTest.java:78)
> 07-28 14:54:10.354: ERROR/Global(725): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
> 07-28 14:54:10.354: ERROR/Global(725): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
> 07-28 14:54:10.354: ERROR/Global(725): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
> 07-28 14:54:10.354: ERROR/Global(725): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
> 07-28 14:54:10.354: ERROR/Global(725): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
> 07-28 14:54:10.354: ERROR/Global(725): at android.os.Handler.dispatchMessage(Handler.java:99)
> 07-28 14:54:10.354: ERROR/Global(725): at android.os.Looper.loop(Looper.java:123)
> 07-28 14:54:10.354: ERROR/Global(725): at android.app.ActivityThread.main(ActivityThread.java:3948)
> 07-28 14:54:10.354: ERROR/Global(725): at java.lang.reflect.Method.invokeNative(Native Method)
> 07-28 14:54:10.354: ERROR/Global(725): at java.lang.reflect.Method.invoke(Method.java:521)
> 07-28 14:54:10.354: ERROR/Global(725): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
> 07-28 14:54:10.354: ERROR/Global(725): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
> 07-28 14:54:10.354: ERROR/Global(725): at dalvik.system.NativeStart.main(Native Method)
patch attached - adding this simple check my xml document is parsed
successfully on android 1.5.
regards,
S. Seide
-------------- next part --------------
diff -ur src/java/org/jdom/input/SAXHandler.java src_patch/java/org/jdom/input/SAXHandler.java
--- src/java/org/jdom/input/SAXHandler.java 2009-07-28 17:46:40.703125000 +0200
+++ src_patch/java/org/jdom/input/SAXHandler.java 2009-07-28 17:31:06.546875000 +0200
@@ -564,7 +564,7 @@
// patch from Mattias Jiderhamn
if ("".equals(attLocalName) && attQName.indexOf(":") == -1) {
attribute = factory.attribute(attQName, atts.getValue(i), attType);
- } else if (!attQName.equals(attLocalName)) {
+ } else if (!attQName.equals(attLocalName) && attQName.length()>0) {
String attPrefix = attQName.substring(0, attQName.indexOf(":"));
Namespace attNs = Namespace.getNamespace(attPrefix,
atts.getURI(i));
More information about the jdom-interest
mailing list