JDK-6613059 : sjsxp issue 42: Same code runs fine on 1.6.0_01 but gives XMLStreamException on 1.6.0_02
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.stream
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-10-04
  • Updated: 2012-04-25
  • Resolved: 2007-10-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
1.4.0 1.4Fixed 6u18Resolved 7Resolved
Description
FULL PRODUCT VERSION :
1.6.0_02

ADDITIONAL OS VERSION INFORMATION :
Seen on different windows version, one of them being:
Microsoft Windows 2000 [versie 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
See the code below. It is a fragment that is used to dynamically build a menu bar depending on the contents of an XML file. The code runs fine when using JRE 1.6.0_01 but gives a javax.xml.stream.XMLStreamException when running in JRE 1.6.0_02. The exception occurs in the line where xer.hasNext() is called (see attached code). The details of the exception are: " ParseError at [row,col]:[1,39]: Message: expected start or end tag". The location mentioned is the character just after the end of the "<?xml version='1.0' encoding='UTF-8'?>" declaration in our XML file. The XML file has a rather simple structure; we do not use any DTD or XML schema.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try the attached code on a file like this:

<?xml version='1.0' encoding='UTF-8'?>
<menubar>
	<menu>
		<id>file</id>
		<item>
			<id>exit</id>
			<method>doExit 0</method>
			<type>all</type>
		</item>
	</menu>
	<menu>
		<id>edit</id>
		<item>
			<id>prefs</id>
			<method>showPrefsWindow 0</method>
			<type>all</type>
		</item>
	</menu>
</menubar>




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The file is parsed.
ACTUAL -
Exception occurs.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,39]
Message: expected start or end tag
	at com.sun.xml.internal.stream.XMLEventReaderImpl.nextTag(Unknown Source)
	at com.koopmanint.util.LisMenuBar.<init>(LisMenuBar.java:51)
	at com.koopmanint.lis.LisMainWindow.getMainMenuBar(LisMainWindow.java:245)
	at com.koopmanint.lis.LisMainWindow.initialize(LisMainWindow.java:137)
	at com.koopmanint.lis.LisMainWindow.<init>(LisMainWindow.java:117)2007-10-02
	at com.koopmanint.lis.LisMainWindow.getInstance(LisMainWindow.java:127)
	at com.koopmanint.lis.LisMain.createAndShowGUI(LisMain.java:97)
	at com.koopmanint.lis.LisMain.access$2(LisMain.java:95)
	at com.koopmanint.lis.LisMain$1.run(LisMain.java:157)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
        XMLInputFactory xif = XMLInputFactoryImpl.newInstance();
        XMLEventReader xer = null;
        try {
            xer = xif.createXMLEventReader(xif.createXMLStreamReader(new FileInputStream(xmlFile)));
        } catch (FileNotFoundException e) {
            log.error("Error while reading XML: " + e.getClass().getName() + " " + e.getMessage());
        } catch (XMLStreamException e) {
            log.error("Error while reading XML: " + e.getClass().getName() + " " + e.getMessage());
        }

        try {
            while (xer.hasNext()) {
                XMLEvent event = xer.nextTag();
                while (event.isEndElement() && !event.isEndDocument()) {
                    event = xer.nextTag();
                }

                if (event.asStartElement().getName().equals(new QName("menu"))) {
                    this.add(addMenu("app.menu", xer, event, al));
                }

                if (event.isEndDocument()) {
                    break;
                }
            }
        } catch (XMLStreamException e) {
            log.warn("Exception while reading " + xmlFile + ": " + e.getClass().getName() + " " + e.getMessage());
        }

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use older JRE (1.6.0_01). This means automatic updates have to be disabled for all our users, which is not desireable.

Release Regression From : 6u1
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION This patch is the same as that for stax-issue-42. XMLEventReader.nextTag() does not handle START_DOCUMENT. The regression in 1.6.0_02 was introduced by the patch for 6489890 in which the initial state of event reader was corrected to start as START_DOCUMENT when created using an XMLStreamReader. Note that nextTag should be used when processing element-only content. The code user submitted would work assuming the AddMenu method handles the menu element and end document event. It may be better to use the END_ELEMENT "menubar" as an indicator to stop the processing with code similar to the following: while (xer.hasNext()) { XMLEvent event = xer.nextTag(); if (event.isEndElement() && event.asEndElement().getName().equals(new QName("menubar"))) { break; } if (event.asStartElement().getName().equals(new QName("menu"))) { addMenu("app.menu", xer, event, al); } }
2007-10-16