This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/commons-secure-xml.git
commit ced43e2b7e29e7a73a2ec0e8c56a300229b5f1e2 Author: Gary Gregory <[email protected]> AuthorDate: Mon Aug 31 10:23:30 2026 -0400 Internal refactoring --- .../java/org/apache/commons/xml/secure/MethodHandleFactory.java | 9 ++++----- .../apache/commons/xml/secure/SecureDocumentBuilderFactory.java | 3 +-- .../org/apache/commons/xml/secure/SecureSAXParserFactory.java | 3 +-- .../java/org/apache/commons/xml/secure/SecureSchemaFactory.java | 3 +-- .../org/apache/commons/xml/secure/SecureTransformerFactory.java | 3 +-- .../org/apache/commons/xml/secure/SecureXMLInputFactory.java | 3 +-- .../java/org/apache/commons/xml/secure/SecureXPathFactory.java | 3 +-- .../org/apache/commons/xml/secure/MethodHandleFactoryTest.java | 4 ++-- 8 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/apache/commons/xml/secure/MethodHandleFactory.java b/src/main/java/org/apache/commons/xml/secure/MethodHandleFactory.java index 029de73..d49837a 100644 --- a/src/main/java/org/apache/commons/xml/secure/MethodHandleFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/MethodHandleFactory.java @@ -33,18 +33,17 @@ interface ThrowableCallable<V> { } /** - * Finds a static method handle for the given class, method name, and method type. + * Finds a static method handle for the given class, method name, where the class is also the return type. * - * @param refc the class to search for the method. + * @param refcAndReturnType the class to search for the method and the return type. * @param name the name of the method. - * @param type the method return type. * @return the method handle, or {@code null} if not found. * @throws SecurityException if a security manager is present and it <a href="MethodHandles.Lookup.html#secmgr">refuses access</a>. * @throws NullPointerException if any argument is null. */ - static MethodHandle findStatic(final Class<?> refc, final String name, final Class<?> returnType) { + static MethodHandle findStatic(final Class<?> refcAndReturnType, final String name) { try { - return MethodHandles.publicLookup().findStatic(refc, name, MethodType.methodType(returnType)); + return MethodHandles.publicLookup().findStatic(refcAndReturnType, name, MethodType.methodType(refcAndReturnType)); } catch (final ReflectiveOperationException e) { return null; } diff --git a/src/main/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactory.java b/src/main/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactory.java index 06bc706..b51ea87 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactory.java @@ -184,8 +184,7 @@ public void setXIncludeAware(final boolean state) { /** Class name of the JDK's built-in default implementation, the Java 8 fallback for {@link #newDefaultInstance()}. */ private static final String JDK_DOCUMENT_BUILDER_FACTORY = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"; - private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(DocumentBuilderFactory.class, "newDefaultInstance", - DocumentBuilderFactory.class); + private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(DocumentBuilderFactory.class, "newDefaultInstance"); /** * Enables namespace awareness on the given factory; the {@code NSInstance} counterpart of each factory method routes its result through here. diff --git a/src/main/java/org/apache/commons/xml/secure/SecureSAXParserFactory.java b/src/main/java/org/apache/commons/xml/secure/SecureSAXParserFactory.java index c761db8..a4d3c1f 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureSAXParserFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureSAXParserFactory.java @@ -175,8 +175,7 @@ public void setXIncludeAware(final boolean state) { /** System property naming the {@link SAXParserFactory} implementation, the JDK's own mechanism for reconfiguring the default parser. */ private static final String SAX_FACTORY_ID = "javax.xml.parsers.SAXParserFactory"; - private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(SAXParserFactory.class, "newDefaultInstance", - SAXParserFactory.class); + private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(SAXParserFactory.class, "newDefaultInstance"); /** * Enables namespace awareness on the given factory; the {@code NSInstance} counterpart of each factory method routes its result through here. diff --git a/src/main/java/org/apache/commons/xml/secure/SecureSchemaFactory.java b/src/main/java/org/apache/commons/xml/secure/SecureSchemaFactory.java index 46b93ee..7aaa4c1 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureSchemaFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureSchemaFactory.java @@ -202,8 +202,7 @@ public void setResourceResolver(final LSResourceResolver resourceResolver) { /** Class name of the JDK's built-in default implementation, the Java 8 fallback for {@link #newDefaultInstance()}. */ private static final String JDK_SCHEMA_FACTORY = "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory"; - private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(SchemaFactory.class, "newDefaultInstance", - SchemaFactory.class); + private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(SchemaFactory.class, "newDefaultInstance"); /** * Returns a new, secure {@link SchemaFactory} of the system-default implementation, supporting W3C XML Schema 1.0. diff --git a/src/main/java/org/apache/commons/xml/secure/SecureTransformerFactory.java b/src/main/java/org/apache/commons/xml/secure/SecureTransformerFactory.java index 88fd5b5..4634104 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureTransformerFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureTransformerFactory.java @@ -359,8 +359,7 @@ public void setURIResolver(final URIResolver resolver) { /** Class name of the JDK's built-in default implementation, the Java 8 fallback for {@link #newDefaultInstance()}. */ private static final String JDK_TRANSFORMER_FACTORY = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"; - private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(TransformerFactory.class, "newDefaultInstance", - TransformerFactory.class); + private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(TransformerFactory.class, "newDefaultInstance"); /** * Returns a new, secure {@link TransformerFactory} of the system-default implementation. diff --git a/src/main/java/org/apache/commons/xml/secure/SecureXMLInputFactory.java b/src/main/java/org/apache/commons/xml/secure/SecureXMLInputFactory.java index 0e7a9d9..60a696a 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureXMLInputFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureXMLInputFactory.java @@ -254,8 +254,7 @@ public void setXMLResolver(final XMLResolver resolver) { /** Class name of the JDK's built-in default implementation, the Java 8 fallback for {@link #newDefaultFactory()}. */ private static final String JDK_XML_INPUT_FACTORY = "com.sun.xml.internal.stream.XMLInputFactoryImpl"; - private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(XMLInputFactory.class, "newDefaultFactory", - XMLInputFactory.class); + private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(XMLInputFactory.class, "newDefaultFactory"); /** * Returns a new, secure {@link XMLInputFactory} of the system-default implementation. diff --git a/src/main/java/org/apache/commons/xml/secure/SecureXPathFactory.java b/src/main/java/org/apache/commons/xml/secure/SecureXPathFactory.java index 0e51819..b550a07 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureXPathFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureXPathFactory.java @@ -120,8 +120,7 @@ public void setXPathVariableResolver(final XPathVariableResolver resolver) { /** Class name of the JDK's built-in default implementation, the Java 8 fallback for {@link #newDefaultInstance()}. */ private static final String JDK_XPATH_FACTORY = "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl"; - private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(XPathFactory.class, "newDefaultInstance", - XPathFactory.class); + private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(XPathFactory.class, "newDefaultInstance"); /** * Returns a new, secure {@link XPathFactory} of the system-default implementation, supporting the default XPath object model. diff --git a/src/test/java/org/apache/commons/xml/secure/MethodHandleFactoryTest.java b/src/test/java/org/apache/commons/xml/secure/MethodHandleFactoryTest.java index 314e242..c6c9d2e 100644 --- a/src/test/java/org/apache/commons/xml/secure/MethodHandleFactoryTest.java +++ b/src/test/java/org/apache/commons/xml/secure/MethodHandleFactoryTest.java @@ -42,13 +42,13 @@ class MethodHandleFactoryTest { @Test void findStaticReturnsHandleForExistingMethod() { - final MethodHandle handle = MethodHandleFactory.findStatic(XMLInputFactory.class, "newInstance", XMLInputFactory.class); + final MethodHandle handle = MethodHandleFactory.findStatic(XMLInputFactory.class, "newInstance"); assertNotNull(handle, "an existing static method must resolve to a handle"); } @Test void findStaticReturnsNullForMissingMethod() { - assertNull(MethodHandleFactory.findStatic(XMLInputFactory.class, "noSuchMethod", void.class), + assertNull(MethodHandleFactory.findStatic(XMLInputFactory.class, "noSuchMethod"), "a missing method must resolve to null"); }
