Fall back to the standard lookup in newDefaultInstance on Android - #62
Merged
garydgregory merged 3 commits intoAug 30, 2026
Merged
Conversation
Android provides neither the Java 9 newDefaultInstance methods nor the JDK's built-in implementation classes, so the DOM and SAX newDefaultInstance methods threw FactoryConfigurationError there. Both now degrade to the standard newInstance() lookup, which Android pins to the platform implementation, preserving the platform-default semantics. The fallback is unreachable on a JVM: Java 9+ resolves the platform method and Java 8 has the built-in class. Assisted-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MbfpcsKig16HfSe6jGhcvh
Android ships no SchemaFactory implementation, but its lookup falls back to exactly the Xerces implementation this library recognizes, so degrading to the standard newInstance(String) lookup gives schema the same platform-default semantics as the DOM and SAX methods. Assisted-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MbfpcsKig16HfSe6jGhcvh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Android,
SecureDocumentBuilderFactory.newDefaultInstance()andSecureSAXParserFactory.newDefaultInstance()threwFactoryConfigurationError: the platform has never shipped the Java 9newDefaultInstancemethods (verified in android.jar API 19-34, on API 33 and API 35 emulators, and in current AOSP libcoremain), and the Java 8 fallback instantiates a desktop-JDK-internal class that does not exist on ART. The newSecureTransformerFactoryTest.securesAssociatedStylesheetSourcesOfEverySupportedShapehit this through its directSecureSAXParserFactory.newXMLReader(false)call (failing run).The DOM and SAX class-name fallbacks now degrade to the standard
newInstance()lookup when the JDK-internal class is unavailable. The degradation tier is unreachable on a JVM (Java 9+ resolves the platform method, Java 8 has the built-in class), and Android's ownnewInstance()is hardcoded to the platform implementation, so the platform-default semantics survive. Scope covers DOM, SAX and schema: DOM and SAX are the factories Android ships with a fixed-classnewInstance(), and the schema lookup, while classpath-dependent, falls back on Android to exactly the Xerces implementation this library recognizes, so all three keep meaningful platform-default semantics; TrAX/XPath/StAX keep their current behavior.Verified: full JVM surefire matrix green; on the API 33 emulator the previously failing TrAX test now passes. The four
newDefault*methods inSecureFactoriesSmokeTeststill assert the old AndroidassertThrows(FactoryConfigurationError)behavior and now fail there; they will be adapted together with the tagging review of the recently added tests in a follow-up.🤖 Generated with Claude Code
https://claude.ai/code/session_01MbfpcsKig16HfSe6jGhcvh