RE: java.lang.ArrayIndexOutOfBoundsException
"David Goldfarb" <[email protected]> Tue, 30 Mar 2004 22:34:50 +0200
| Newsgroups | gmane.text.xml.xmlpull.devel |
|---|---|
| Organization | Degel Software Ltd. |
| Message-ID | <[email protected]> |
Hi,
I hit the same problem a few days ago, on a very similar project (in my
case, a Wireless Village client). I also reinserted the commented out code,
but I believe that the last line in the commented-out code
(nspCounts[depth] = nspCounts[depth - 1];)
is not needed and should remain out.
You will soon hit another problem too, in the method nextImpl(), the
handling of code Wbxml.SWITCH_PAGE is not quite correct; it needs to reset
the nextId to the magic value one more time, or the second peekId() will
return the wrong value.
int id = peekId ();
while(id == Wbxml.SWITCH_PAGE){
nextId = -2; <=== need to add this line
selectPage(readByte(), true);
id = peekId();
Finally, you will need to add handlers into the parseWapExtension() method.
However, unlike the earlier changes, the changes I made here are
WV-specific, so I'm not comfortable posting them here where someone might
mistakenly introduce them into the WBXML code base or another project.
Please contact me privately if you want those changes too. (Also, I'll need
my client's permission, is that code is closer to areas they view as
proprietary)
Meta-question: I had meant to report these and other changes, but haven't
yet had the time to figure out who was the code maintainer of the WBXML
code. If the appropriate folks are reading this, please drop me a line.
David
------------------------------------------
Degel Software Ltd.
David Goldfarb
President
[email protected]
7 Ha'Iris St.
Beit Shemesh, 99512
Israel
tel: +972 (2) 999-5721
fax: +972 (2) 991-6718
mobile: +972 (67) 230-120
-----Original Message-----
From: floriola2000 [mailto:[email protected]]
Sent: Tuesday, March 30, 2004 10:15 PM
To: [email protected]
Subject: [xmlpull-dev] java.lang.ArrayIndexOutOfBoundsException
Hi,
I am trying to decode the wbxml Login-Request document sent by a
Wireless Village phone. I have captured this document into a file
called file.wbxml using a sniffer, and I made a simple parser, like
below.
I am using the latest kxml2 version from CVS and the xmlpull
xmlpull_1_1_3_4a_src.zip, without any modifications.
Here is my code:
public class WvParser extends WV {
// Do nothing
public WvParser() {};
}
public class WvTestParser {
public static void main(String[] argv) throws Exception {
WvParser wp = new WvParser();
XmlPullParser xp = wp.createParser();
xp.setInput(new FileInputStream("file.wbxml"), null);
XmlSerializer xs = new KXmlSerializer();
xs.setOutput(System.out, null);
new Roundtrip(xp, xs).roundTrip();
}
}
Now when I run this code, I get the following error:
<?xml version='1.0' ?><WV-CSP-Message xmlns="http://www.wireless-
village.org/CSP1.1"><Session><SessionDescriptor>
java.lang.ArrayIndexOutOfBoundsException: 4
at org.kxml2.wap.WbxmlParser.getNamespaceCount
(WbxmlParser.java:113)
at Roundtrip.writeStartTag(Roundtrip.java:36)
at Roundtrip.writeToken(Roundtrip.java:69)
at Roundtrip.roundTrip(Roundtrip.java:122)
at WvTestParser.main(WvTestParser.java:27)
Exception in thread "main"
The problem is this java.lang.ArrayIndexOutOfBoundsException
I looked into the code and in WbxmlParser.java file, around line 885,
I found the following commented code:
/* if (depth >= nspCounts.length) {
int[] bigger = new int[depth + 4];
System.arraycopy(nspCounts, 0, bigger, 0,
nspCounts.length);
nspCounts = bigger;
}
nspCounts[depth] = nspCounts[depth - 1]; */
If you uncomment this code, this ArrayIndexOutOfBoundsException
error disapear.
I also noticed that the code that I have uncommentd is doing the same
thing like ensureCapacity method, the diference is that
ensureCapacity has a String[] as first argument and returns a String
[], while the uncomented code is using an int[] nspCounts.
Would it be possible that you overload this ensureCapacity method, so
that it can handle also int[]? In this way the code that I have
uncommented can be changed like this:
nspCounts = ensureCapacity(nspCounts, depth + 4);
nspCounts[depth] = nspCounts[depth - 1];
Would it also be possible to keep this code uncommented?
Thanks and best regards,
Floriola
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/xmlpull-dev/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/