Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#34] Make setFeature calls optional #56

Merged
merged 1 commit into from Nov 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/main/java/org/apache/log4j/xml/DOMConfigurator.java
Expand Up @@ -788,6 +788,16 @@ public String toString() {
doConfigure(action, repository);
}

private final void setFeature(final DocumentBuilderFactory dbf, final String feature, final boolean value) {
try {
dbf.setFeature(feature, value);
} catch (Exception e) {
LogLog.warn("Failed to set DocumentBuilderFactory feature " + feature + ".", e);
} catch (AbstractMethodError e) {
LogLog.warn("Failed to set DocumentBuilderFactory feature " + feature + ". Missing DocumentBuilderFactory.setFeature() method?", e);
}
}

private final void doConfigure(final ParseAction action, final LoggerRepository repository)
throws FactoryConfigurationError {
DocumentBuilderFactory dbf = null;
Expand All @@ -806,8 +816,8 @@ private final void doConfigure(final ParseAction action, final LoggerRepository
try {
dbf.setValidating(true);
// prevent XXE attacks
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
setFeature(dbf, "http://xml.org/sax/features/external-general-entities", false);
setFeature(dbf, "http://xml.org/sax/features/external-parameter-entities", false);

DocumentBuilder docBuilder = dbf.newDocumentBuilder();

Expand All @@ -821,9 +831,6 @@ private final void doConfigure(final ParseAction action, final LoggerRepository
Thread.currentThread().interrupt();
}
LogLog.error("Could not parse " + action.toString() + ".", e);
} catch (AbstractMethodError e) {
LogLog.error("Failed to parse XML file. Missing DocumentBuilderFactory.setFeature() method?", e);
throw e;
}
}

Expand Down