Skip to content

Commit

Permalink
Fix #196: move endDocument() call to outside of finally-block (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 23, 2024
1 parent 4a6d227 commit 92c816e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Expand Up @@ -8,6 +8,8 @@ Project: woodstox

#134: Increase JDK baseline to Java 8
#194: Remove `QNameCreator` compatibility class
#196: WstxSAXParser error handling when used with JAXB validation
(reported by @winfriedgerlach)

6.6.0 (15-Jan-2024)

Expand Down
29 changes: 17 additions & 12 deletions src/main/java/com/ctc/wstx/sax/WstxSAXParser.java
Expand Up @@ -584,9 +584,8 @@ public void parse(InputSource input) throws SAXException
mContentHandler.startDocument();
}

/* Note: since we are reusing the same config instance, need to
* make sure state is not carried forward. Thus:
*/
// Note: since we are reusing the same config instance, need to
// make sure state is not carried forward. Thus:
cfg.resetState();

try {
Expand Down Expand Up @@ -621,14 +620,9 @@ public void parse(InputSource input) throws SAXException
mAttrCollector = mScanner.getAttributeCollector();
mElemStack = mScanner.getInputElementStack();
fireEvents();
} catch (IOException io) {
throwSaxException(io);
} catch (XMLStreamException strex) {
throwSaxException(strex);
} catch (Exception e) {
throwSaxException(e);
} finally {
if (mContentHandler != null) {
mContentHandler.endDocument();
}
// Could try holding onto the buffers, too... but
// maybe it's better to allow them to be reclaimed, if
// needed by GC
Expand All @@ -650,6 +644,12 @@ public void parse(InputSource input) throws SAXException
} catch (IOException ioe) { }
}
}
// 20-Feb-2024, tatu: Was formerly done in finally-block for some
// reason; but makes more sense to only be done on happy path
// (as per [woodstox-core#196]
if (mContentHandler != null) {
mContentHandler.endDocument();
}
}

@Override
Expand Down Expand Up @@ -1281,8 +1281,13 @@ public void dtdInternalEntityDecl(String name, String value)
private void throwSaxException(Exception src)
throws SAXException
{
SAXParseException se = new SAXParseException(src.getMessage(), /*(Locator)*/ this, src);
ExceptionUtil.setInitCause(se, src);
SAXParseException se;
if (src instanceof SAXParseException) {
se = (SAXParseException) src;
} else {
se = new SAXParseException(src.getMessage(), /*(Locator)*/ this, src);
ExceptionUtil.setInitCause(se, src);
}
if (mErrorHandler != null) {
mErrorHandler.fatalError(se);
}
Expand Down

0 comments on commit 92c816e

Please sign in to comment.