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

Call reset on reusable SAXParser instance #742

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lrytz
Copy link
Member

@lrytz lrytz commented Nov 11, 2024

Discussion: #176 (comment)

Copy link
Contributor

@dubinsky dubinsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to me what is gained by this change...

def parser: SAXParser = parserInstance.get
def parser: SAXParser = {
val p = parserInstance.get
p.reset()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-reset on get leads to surprising changes in behavior, e.g. non-persistence of the settings on XMLLoader.reader, as witnessed by the changes to the test above.
Better place for auto-reset seems to be FactoryAdapter.loadDocument(), but it will then apply to all readers, not just the default one...
Better still would be - in my opinion - not to reuse parsers, readers and factory adapters and not to use thread-locals.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So revert #176?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not going to campaign for reverting it, but I am not a fan ;)

override def warning(e: SAXParseException): Unit = gotAnError = true
override def error(e: SAXParseException): Unit = gotAnError = true
override def fatalError(e: SAXParseException): Unit = gotAnError = true
})
try {
XML.loadString("<a>")
XML.adapter.loadDocument(Source.fromString("<a>"), reader)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to make XMLLoader.adapter, NoBindingFactoryAdapter and FactoryAdapter private at some point (and remove some of them altogether), and add XMLLoader.loadDocument(inputSource: InputSource, reader: XMLReader)...

@lrytz
Copy link
Member Author

lrytz commented Nov 12, 2024

It is not clear to me what is gained by this change...

It's really more of a guess... In a non-public codebase we have an UnsafeXML object that's similar to XML but before the safe defaults (#177). We recently applied the same ThreadLocal caching to UnsafeXML as was done in #176 and saw some SaxParserException. But I haven't followed through to understand what's going on exactly or if reset actually fixes it, I'll do that.

Thanks for taking a look.

@lrytz
Copy link
Member Author

lrytz commented Nov 20, 2024

I haven't followed through to understand what's going on exactly or if reset actually fixes it, I'll do that.

Didn't manage to reproduce the failure we saw and suspect would be fixed by this PR.

So that leaves as justification that "it seems right" to call reset, according to the Javadocs.

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

Successfully merging this pull request may close these issues.

2 participants