Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copyEventFromReader() ArrayIndexOutOfBoundsException #97

Closed
dan2097 opened this issue Dec 6, 2019 · 4 comments
Closed

copyEventFromReader() ArrayIndexOutOfBoundsException #97

dan2097 opened this issue Dec 6, 2019 · 4 comments
Milestone

Comments

@dan2097
Copy link

dan2097 commented Dec 6, 2019

The issue can be reproduced by (I attach test.txt):

WstxInputFactory inputFactory = new WstxInputFactory();
WstxOutputFactory outputFactory = new WstxOutputFactory();
String text = FileUtils.readFileToString(new File("test.txt"), "UTF-8");
ByteArrayOutputStream bios = new ByteArrayOutputStream();
try {
  XMLStreamReader2 reader = (XMLStreamReader2) inputFactory.createXMLStreamReader(new StringReader(text));
  XMLStreamWriter2 writer = (XMLStreamWriter2) outputFactory.createXMLStreamWriter(bios, "UTF-8");
  while (reader.hasNext()) {
	reader.next();
	writer.copyEventFromReader(reader, false);
  }
} catch (Exception e) {
  e.printStackTrace();
}

and produces:

java.lang.ArrayIndexOutOfBoundsException: -1
	at com.ctc.wstx.sr.BasicStreamReader.readAndWriteText(BasicStreamReader.java:5185)
	at com.ctc.wstx.sr.BasicStreamReader.getText(BasicStreamReader.java:1431)
	at com.ctc.wstx.sw.BaseStreamWriter.copyEventFromReader(BaseStreamWriter.java:857)
	at test.WoodstoxTest.main(WoodstoxTest.java:27)

To produce the issue all of the following seem to need to be true:

  • copyEventFromReader is called with a second parameter of false rather than true
  • The root element has a lang attribute
  • The element text content is over a certain length

test.txt

EDIT: I reproduced this issue on Woodstox 4.4.1 and 6.0.2

@cowtowncoder
Copy link
Member

Thank you for reporting the problem.

@cowtowncoder cowtowncoder added this to the 6.0.3 milestone Dec 6, 2019
@cowtowncoder cowtowncoder changed the title copyEventFromReader ArrayIndexOutOfBoundsException copyEventFromReader() ArrayIndexOutOfBoundsException Dec 6, 2019
@cowtowncoder
Copy link
Member

Turns out to be another boundary condition; also required use of \r as linefeed (MacOS I think?) to trigger. Fixed, will be in 6.0.3 once I release that (might be time to do it tonight, 3rd fix).

@dan2097
Copy link
Author

dan2097 commented Dec 9, 2019

Thanks for the quick fix and release. I hadn't actually noticed that \r was being used to indicate new lines!
\r was used by legacy versions of MacOS, but current versions use \n.

@cowtowncoder
Copy link
Member

Ah. Makes sense that Macs have switched, perhaps with MacOS X when switching to unix kernel... I just remembered that once upon a time something was using \r. And XML definitely supports 3 linefeed combinations (\n, \r, \r\n).

Also: 6.0.3 should be available now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants