Skip to content

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 ;)

})
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.

@SethTisue
Copy link
Member

@dubinsky where do we stand here, any idea?

@dubinsky
Copy link
Contributor

@dubinsky where do we stand here, any idea?

As mentioned in #742 (comment) and #742 (comment), I do not see this change as a move in the right direction (see #765 for context).

According to #742 (comment), suspicion that this change fixes a problem has been falsified, and the only motivation for merging it is that it "feels right".

Well, it does not feel right to me, since it leads to surprising (to me ;)) changes in behavior, e.g. non-persistence of the settings on XMLLoader.reader, But if this still feels right to @lrytz, let's just do it ;)

@lrytz?

@SethTisue
Copy link
Member

thanks. I'll presumptively close — @lrytz can reopen if he likes

@SethTisue SethTisue closed this Nov 12, 2025
@lrytz
Copy link
Member Author

lrytz commented Nov 12, 2025

suspicion that this change fixes a problem has been falsified

Maybe not falsified, I could not come up with a reproducer.

it does not feel right to me, since it leads to surprising (to me ;)) changes in behavior, e.g. non-persistence of the settings on XMLLoader.reader

Right, the PR breaks the usage pattern of XML.reader.setErrorHandler(...); XML.load(...). Currently the settings change is persisted. But that's per thread, since the parser instance is ThreadLocal, which could also cause confusing bugs.

Though thinking about it, this global customization did not work before #176, and it would not work if we reverted it?

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.

3 participants