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 630bfd30f006276f102624d6a707bc8aada09709 Author: Gary Gregory <[email protected]> AuthorDate: Mon Aug 31 10:12:06 2026 -0400 Internal refactoring --- .../java/org/apache/commons/xml/secure/MethodHandleFactory.java | 6 +++--- .../org/apache/commons/xml/secure/SecureDocumentBuilderFactory.java | 3 +-- .../java/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 +-- .../java/org/apache/commons/xml/secure/SecureXMLInputFactory.java | 3 +-- src/main/java/org/apache/commons/xml/secure/SecureXPathFactory.java | 3 +-- .../java/org/apache/commons/xml/secure/MethodHandleFactoryTest.java | 4 ++-- 8 files changed, 11 insertions(+), 17 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 6267380..6ee8526 100644 --- a/src/main/java/org/apache/commons/xml/secure/MethodHandleFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/MethodHandleFactory.java @@ -37,14 +37,14 @@ interface ThrowableCallable<V> { * * @param refc the class to search for the method. * @param name the name of the method. - * @param type the method type. + * @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 MethodType type) { + static MethodHandle findStatic(final Class<?> refc, final String name, final Class<?> returnTpe) { try { - return MethodHandles.publicLookup().findStatic(refc, name, type); + return MethodHandles.publicLookup().findStatic(refc, name, MethodType.methodType(returnTpe)); } 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 819947e..06bc706 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureDocumentBuilderFactory.java @@ -18,7 +18,6 @@ package org.apache.commons.xml.secure; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodType; import java.util.Objects; import javax.xml.XMLConstants; @@ -186,7 +185,7 @@ public void setXIncludeAware(final boolean state) { 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", - MethodType.methodType(DocumentBuilderFactory.class)); + DocumentBuilderFactory.class); /** * 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 936ee9e..c761db8 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureSAXParserFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureSAXParserFactory.java @@ -18,7 +18,6 @@ package org.apache.commons.xml.secure; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodType; import java.util.Objects; import javax.xml.XMLConstants; @@ -177,7 +176,7 @@ public void setXIncludeAware(final boolean state) { private static final String SAX_FACTORY_ID = "javax.xml.parsers.SAXParserFactory"; private static final MethodHandle MH_newDefaultInstance = MethodHandleFactory.findStatic(SAXParserFactory.class, "newDefaultInstance", - MethodType.methodType(SAXParserFactory.class)); + SAXParserFactory.class); /** * 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 e2613c8..46b93ee 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureSchemaFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureSchemaFactory.java @@ -18,7 +18,6 @@ package org.apache.commons.xml.secure; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodType; import java.util.Objects; import javax.xml.XMLConstants; @@ -204,7 +203,7 @@ public void setResourceResolver(final LSResourceResolver resourceResolver) { 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", - MethodType.methodType(SchemaFactory.class)); + SchemaFactory.class); /** * 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 57e81e5..88fd5b5 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureTransformerFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureTransformerFactory.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodType; import java.util.Objects; import java.util.function.Supplier; @@ -361,7 +360,7 @@ public void setURIResolver(final URIResolver resolver) { 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", - MethodType.methodType(TransformerFactory.class)); + TransformerFactory.class); /** * 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 8c1784a..0e7a9d9 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureXMLInputFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureXMLInputFactory.java @@ -20,7 +20,6 @@ import java.io.InputStream; import java.io.Reader; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodType; import java.util.Objects; import javax.xml.stream.EventFilter; @@ -256,7 +255,7 @@ public void setXMLResolver(final XMLResolver resolver) { 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", - MethodType.methodType(XMLInputFactory.class)); + XMLInputFactory.class); /** * 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 8450345..0e51819 100644 --- a/src/main/java/org/apache/commons/xml/secure/SecureXPathFactory.java +++ b/src/main/java/org/apache/commons/xml/secure/SecureXPathFactory.java @@ -18,7 +18,6 @@ package org.apache.commons.xml.secure; import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodType; import java.util.Objects; import javax.xml.XMLConstants; @@ -122,7 +121,7 @@ public void setXPathVariableResolver(final XPathVariableResolver resolver) { 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", - MethodType.methodType(XPathFactory.class)); + XPathFactory.class); /** * 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 c3f1f58..314e242 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", MethodType.methodType(XMLInputFactory.class)); + final MethodHandle handle = MethodHandleFactory.findStatic(XMLInputFactory.class, "newInstance", XMLInputFactory.class); assertNotNull(handle, "an existing static method must resolve to a handle"); } @Test void findStaticReturnsNullForMissingMethod() { - assertNull(MethodHandleFactory.findStatic(XMLInputFactory.class, "noSuchMethod", MethodType.methodType(void.class)), + assertNull(MethodHandleFactory.findStatic(XMLInputFactory.class, "noSuchMethod", void.class), "a missing method must resolve to null"); }
