Skip to content

Fall back to the standard lookup in newDefaultInstance on Android - #62

Merged
garydgregory merged 3 commits into
apache:mainfrom
ppkarwasz:fix/android-newdefaultinstance
Aug 30, 2026
Merged

Fall back to the standard lookup in newDefaultInstance on Android#62
garydgregory merged 3 commits into
apache:mainfrom
ppkarwasz:fix/android-newdefaultinstance

Conversation

@ppkarwasz

@ppkarwasz ppkarwasz commented Aug 30, 2026

Copy link
Copy Markdown
Member

On Android, SecureDocumentBuilderFactory.newDefaultInstance() and SecureSAXParserFactory.newDefaultInstance() threw FactoryConfigurationError: the platform has never shipped the Java 9 newDefaultInstance methods (verified in android.jar API 19-34, on API 33 and API 35 emulators, and in current AOSP libcore main), and the Java 8 fallback instantiates a desktop-JDK-internal class that does not exist on ART. The new SecureTransformerFactoryTest.securesAssociatedStylesheetSourcesOfEverySupportedShape hit this through its direct SecureSAXParserFactory.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 own newInstance() 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-class newInstance(), 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 in SecureFactoriesSmokeTest still assert the old Android assertThrows(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

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
@garydgregory
garydgregory merged commit 2b41858 into apache:main Aug 30, 2026
15 of 17 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