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-xml.git
The following commit(s) were added to refs/heads/main by this push:
new 71d4a36 Restrict DocumentBuilderHardener.setFeature() to catch
ParserConfigurationException instead of Exception.
71d4a36 is described below
commit 71d4a36c130f7fb8624b0f6fc6833944b6a37087
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Aug 26 13:38:45 2026 -0400
Restrict DocumentBuilderHardener.setFeature() to catch
ParserConfigurationException instead of Exception.
---
.../org/apache/commons/xml/DocumentBuilderHardener.java | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/xml/DocumentBuilderHardener.java
b/src/main/java/org/apache/commons/xml/DocumentBuilderHardener.java
index 5f5e7d4..18f9a97 100644
--- a/src/main/java/org/apache/commons/xml/DocumentBuilderHardener.java
+++ b/src/main/java/org/apache/commons/xml/DocumentBuilderHardener.java
@@ -20,6 +20,8 @@
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathFactory;
import org.xml.sax.EntityResolver;
@@ -56,10 +58,19 @@ static DocumentBuilderFactory harden(final
DocumentBuilderFactory factory) {
return new HardeningDocumentBuilderFactory(factory);
}
+ /**
+ * Sets a feature on the given factory, throwing a {@link
HardeningException} if the implementation does not recognize it.
+ *
+ * @param factory The factory to harden.
+ * @param feature The feature to set.
+ * @param value The value to set.
+ * @throws HardeningException Thrown if this {@link XPathFactory} or the
{@code XPath}s it creates cannot support this feature or if {@code feature} is
+ * {@code null}.
+ */
private static void setFeature(final DocumentBuilderFactory factory, final
String feature, final boolean value) {
try {
factory.setFeature(feature, value);
- } catch (final Exception e) {
+ } catch (final ParserConfigurationException e) {
throw HardeningException.settingFailed("feature", feature,
factory, e);
}
}