Skip to content

Use FactoryAdapter as ContentHandler crashes #764

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

Open
lrytz opened this issue Jun 6, 2025 · 1 comment · May be fixed by #765
Open

Use FactoryAdapter as ContentHandler crashes #764

lrytz opened this issue Jun 6, 2025 · 1 comment · May be fixed by #765

Comments

@lrytz
Copy link
Member

lrytz commented Jun 6, 2025

This used to work a while ago

  @UnitTest
  def contentHandler(): Unit = {
    val p = defaultParserFactory.newSAXParser()
    val handler = new parsing.NoBindingFactoryAdapter
    val input = new ByteArrayInputStream("<hello>world</hello>".getBytes("UTF-8"))
    p.parse(input, handler)
    val n: Node = handler.rootElem
  }

This bypasses FactoryAdapter.loadDocument, which is used internally within scala.xml.

Currently:

I came across some code at a customer that uses NoBindingFactoryAdapter as a ContentHandler in their internal XML library to convert to scala.xml.

I can work around it by overriding def endDocument(), getting out the rootElem and avoid calling super.endDocument().

I don't know if the use case should be supported?

@lrytz lrytz linked a pull request Jun 6, 2025 that will close this issue
@dubinsky
Copy link
Contributor

dubinsky commented Jun 6, 2025

I don't know if the use case should be supported?

I do not think it should be. In fact, I do not think that Scala XML should expose any "content handlers" or "factory adapters" at all - methods like XML.load(InputStteam) seem sufficient...

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 a pull request may close this issue.

2 participants