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

Reading comment comments after Root Element closed sometimes throws NullPointerException #58

Closed
GuoHuiChen opened this issue Jul 23, 2018 · 8 comments
Labels
active Issue being actively investigated
Milestone

Comments

@GuoHuiChen
Copy link

TextBuffer.recycle()
206 char[] buf = mCurrentSegment;
207 mCurrentSegment = null;
this.mHasSegments = false; //MUST set false
208 mConfig.freeMediumCBuffer(buf);

284 if (mHasSegments) {
clearSegments();

1050 char[] curr = mCurrentSegment;
1051 int max = curr.length - mCurrentSize; //NPE

@GuoHuiChen
Copy link
Author

430016_NG0405_20180720_V01.zip
This is the sample XML.

Exception in thread "main" java.lang.NullPointerException
at com.ctc.wstx.util.TextBuffer.append(TextBuffer.java:1050)
at com.ctc.wstx.util.TextBuffer.resetWithCopy(TextBuffer.java:291)
at com.ctc.wstx.sr.BasicStreamReader.readComment(BasicStreamReader.java:3908)
at com.ctc.wstx.sr.BasicStreamReader.finishToken(BasicStreamReader.java:3808)
at com.ctc.wstx.sr.BasicStreamReader.safeFinishToken(BasicStreamReader.java:3741)
at com.ctc.wstx.sr.BasicStreamReader.getText(BasicStreamReader.java:889)

@GuoHuiChen
Copy link
Author

Please fix this bug, Thank you!

@cowtowncoder
Copy link
Member

@GuoHuiChen Thank you for reporting the problem.

I tried simplest code I can do that creates XMLStreamReader for test file, but I did not get exception.
So I would like to know what is different with your usage. Could you add code you are using for reading the contents? Or something to trigger the exception.

@GuoHuiChen
Copy link
Author

Thank you for your response. @cowtowncoder (url)
TestReadCommentAfterRoot.zip

Put the 430016_NG0405_20180720_V01.xml in C:\temp directory.
run the test

Exception in thread "main" java.lang.NullPointerException
at com.ctc.wstx.util.TextBuffer.append(TextBuffer.java:1051)
at com.ctc.wstx.util.TextBuffer.resetWithCopy(TextBuffer.java:292)
at com.ctc.wstx.sr.BasicStreamReader.readComment(BasicStreamReader.java:3843)
at com.ctc.wstx.sr.BasicStreamReader.finishToken(BasicStreamReader.java:3743)
at com.ctc.wstx.sr.BasicStreamReader.safeFinishToken(BasicStreamReader.java:3676)
at com.ctc.wstx.sr.BasicStreamReader.getText(BasicStreamReader.java:860)
at TestReadCommentAfterRoot.test(TestReadCommentAfterRoot.java:50)
at TestReadCommentAfterRoot.main(TestReadCommentAfterRoot.java:64)

@GuoHuiChen
Copy link
Author

Please fix this bug!

@cowtowncoder
Copy link
Member

cowtowncoder commented Sep 16, 2018

@GuoHuiChen At this point I will not have much time to work on OSS, and when I do, I will have to think carefully what to work on. Comments asking for speedy work will not help, and sometimes may even put the issue on bottom of the stack.

@cowtowncoder cowtowncoder added active Issue being actively investigated and removed test-needed labels Jul 14, 2019
@cowtowncoder
Copy link
Member

I am able to reproduce the issue, hope to solve today -- thank you for reporting this.
The issue is that the underlying buffer is released on main xml tree closing, but then needing it to access COMMENT (or PROCESSING_INSTRUCTION) content. So need to figure out best way to avoid the problem; either by not releasing buffer as early, or, possibly, verifying is it is reallocated as needed.

@cowtowncoder cowtowncoder changed the title Comment after Root Element read may NullPointerException Reading comment comments after Root Element closed sometimes throws NullPointerException Jul 15, 2019
@cowtowncoder cowtowncoder added this to the 5.3.0 milestone Jul 15, 2019
@cowtowncoder
Copy link
Member

Fixed, will release 5.3.0 later today.

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

No branches or pull requests

2 participants