Delegate the Java 18 XPathFactory property methods - #76
Merged
garydgregory merged 2 commits intoSep 1, 2026
Conversation
Java 18 added setProperty and getProperty to XPathFactory, with defaults that throw UnsupportedOperationException and an override in the JDK implementation that accepts its jdk.xml.xpath* limits. The wrapper is compiled against the Java 8 API, so it inherited those defaults and answered for the delegate: on Java 18 or later a caller could neither tighten nor read a limit through a secure factory, though nothing could be loosened either. Delegate both through method handles, the way newDefaultInstance already reaches a later-release static method. Neither carries @OverRide, which would not compile at release 8; each overrides at run time where the platform declares the method, and reports the inherited UnsupportedOperationException where it does not. The tests reach the pair reflectively for the same reason, which is also how a Java 18 caller resolves it, and skip on a platform without the methods. Assisted-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CLnTBsvmYtxzNTWVGNyz33
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.
Java 18 added
setProperty(String, String)andgetProperty(String)tojavax.xml.xpath.XPathFactory. Their default implementations throwUnsupportedOperationException, and the JDK'sXPathFactoryImploverrides both to accept itsjdk.xml.xpath*processing limits.This library compiles against the Java 8 API, so the wrapper overrode only the methods that existed there and inherited those defaults. On Java 18 or later that meant a secured factory answered
UnsupportedOperationExceptionfor a property the delegate would have accepted: an operator could neither tightenjdk.xml.xpathExprGrpLimitand friends per factory, nor read back the effective value to audit it. It contradicts the package Javadoc's promise that "features, properties, and attributes delegate to" the implementation.Nothing could be loosened this way either — the failure is loud and in the safe direction — so this is a limitation of the wrapper rather than a weakening of the securing.
Both methods are now delegated through method handles, the way
newDefaultInstancealready reaches a static method added in a later release.MethodHandleFactorygains a generalfindVirtualcompanion to its existingfindStatic.Two things a reviewer will want to know:
@Override, and neither can. Atrelease 8the supertype declares no such method, so the annotation would not compile. They override at run time on Java 18 or later, which is the point; both carry a Javadoc note saying so, since the natural instinct is to add the annotation.UnsupportedOperationException, matching the behaviour that release inherits — though the path is unreachable through anXPathFactoryreference there, since the method does not exist to be called.The delegate's own exceptions pass through unwrapped, so an unrecognised property still surfaces its
IllegalArgumentException.Tests
Gated on the presence of the method rather than on a version string:
delegatesTheJava18PropertyApireportsAnUnknownPropertyLikeTheDelegateThey reach the pair reflectively — the suite compiles at
release 8too — which also means they exercise exactly the runtime dispatch a Java 18 caller gets. Both were verified to fail with the delegation removed, so they discriminate rather than passing vacuously.Full surefire matrix green on JDK 17 and on JDK 25.
🤖 Generated with Claude Code