Bug 32539 - gnu.xml.stream.XMLParser: hasNext() assumes next() to follow immediately
Summary: gnu.xml.stream.XMLParser: hasNext() assumes next() to follow immediately
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: xml (show other bugs)
Version: 0.93
: P3 normal
Target Milestone: 0.96
Assignee: chris burdess
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-28 18:47 UTC by Kevin Wolf
Modified: 2007-07-28 15:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-07-16 18:20:40


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Wolf 2007-06-28 18:47:14 UTC
The implementation of gnu.xml.stream.XMLParser.hasNext() seems to assume that it is immediately followed by next(). This may lead to wrong results of some other functions called after hasNext() but before next().

I expected the following code to produce the same output twice, each line starting with "x = x" (event and reader.getEventType() should be the same), as it does in Sun's implementation. In Classpath implementation the second line prints "x = y" where x in general is different from y (and y is the type of the following event).

int event = reader.getEventType();
System.out.println(event + "=" + reader.getEventType() + "; hasNext = " + reader.hasNext());
System.out.println(event + "=" + reader.getEventType() + "; hasNext = " + reader.hasNext());
Comment 1 cvs-commit@developer.classpath.org 2007-07-28 15:38:34 UTC
Subject: Bug 32539

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Changes by:	Chris Burdess <dog>	07/07/28 15:38:14

Modified files:
	.              : ChangeLog 
	gnu/xml/stream : XMLParser.java 

Log message:
	2007-07-28  Chris Burdess  <dog@gnu.org>
	
		PR 32539
		* gnu/xml/stream/XMLParser.java: don't call next() during hasNext().

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.9355&r2=1.9356
http://cvs.savannah.gnu.org/viewcvs/classpath/gnu/xml/stream/XMLParser.java?cvsroot=classpath&r1=1.33&r2=1.34



Comment 2 chris burdess 2007-07-28 15:40:00 UTC
I have committed a patch to avoid calling next() in order to determine whether there is a next event, which solves this problem.