Skip to content

fix(sip-core): construct Woodstox StAX factories directly - #536

Merged
kiivihal merged 1 commit into
mainfrom
orc/woodstox-factories
Nov 19, 2026
Merged

kiivihal merged 1 commit into
mainfrom
orc/woodstox-factories

Conversation

@zemyatin

Copy link
Copy Markdown
Contributor

Problem

Running Narthex locally (sbt run, Play dev mode), processing brabantse-gebouwen gave 1,000 valid and 2,041 invalid records. Every invalid record failed with the same error:

java.lang.ClassCastException: com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl
  cannot be cast to org.codehaus.stax2.XMLStreamReader2 (... loader play.runsupport.NamedURLClassLoader)
  at eu.delving.groovy.MetadataRecordFactory.metadataRecordFrom(MetadataRecordFactory.java:65)

Production processes the same dataset without errors.

Cause

XMLToolFactory.xmlInputFactory() called WstxInputFactory.newInstance(). That method is the static XMLInputFactory.newInstance() inherited from XMLInputFactory, which looks up an implementation through the thread context class loader; it does not construct a Woodstox factory. Under Play's dev-mode class loader, some worker threads can't see Woodstox and get the JDK parser instead. MetadataRecordFactory then casts the reader to XMLStreamReader2 and fails.

Fix

XMLToolFactory now constructs WstxInputFactory, WstxOutputFactory and WstxEventFactory directly. The output and event factories used the same newInstance() lookup. Nothing casts their results today, but Woodstox registers itself as the service for all three, so production already resolves them to Woodstox. Constructing them directly keeps that behaviour and removes the dependency on the class loader.

TestXMLToolFactory covers this:

  • all three factories are Woodstox, and the input factory's readers are XMLStreamReader2;
  • a thread whose context class loader can't see Woodstox still gets a WstxInputFactory. This test fails on main with XMLInputFactoryImpl, which is the bug.

mvn test -pl sip-core on Java 21: 160 tests, 0 failures.

Follow-up

Narthex pins sip-core 1.4.1-RC1, so it only picks this up after a release and a version bump in Narthex. That's your call.

WstxInputFactory.newInstance() is the inherited static
XMLInputFactory.newInstance(), a lookup through the thread context class
loader. Under Play's dev-mode loader some Narthex worker threads got the
JDK parser, and MetadataRecordFactory's cast to XMLStreamReader2 failed
every record. Construct the input, output and event factories directly.
@zemyatin
zemyatin requested a review from kiivihal November 18, 2026 15:47
@kiivihal
kiivihal merged commit 2b4e98e into main Nov 19, 2026
10 checks passed
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