[ 
https://issues.apache.org/jira/browse/LOG4J2-3531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17551482#comment-17551482
 ] 

Simo Nikula commented on LOG4J2-3531:
-------------------------------------

I agree that identifying specific error case is dofficult.
How about refactoring error handling so that any exception would trigger 
attempt without include. Other scenarios could also be added and handled.
Testing with debugger is easy as e.g. NullPointer can be triggered by setting 
documentBuilder to null after getting it.
{code:java}
            Document document=null;
            DocumentBuilder documentBuilder=null;
int maxTries=2;
boolean requestInclude=true;
for(int attempt=0;document==null&&attempt<maxTries;attempt++){
            try {
                documentBuilder = newDocumentBuilder(requestInclude);
                document = documentBuilder.parse(source);
            } catch (final Exception e) {
                    LOGGER.info("Getting newDocumentBuilder failed", e);
switch(attempt){
case 0:
                    LOGGER.info("Trying newDocumentBuilder without XInclude");
requestInclude=false;
break;
default:
       throw e;
}
{code}


> log4j2.xml cannot be parsed on WebSphere
> ----------------------------------------
>
>                 Key: LOG4J2-3531
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3531
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configurators
>    Affects Versions: 2.17.2
>            Reporter: Simo Nikula
>            Assignee: Piotr Karwasz
>            Priority: Minor
>
> Basically similar as LOG4J2-1127
> {noformat}
> ERROR StatusLogger Error parsing ..log4j2.xml
> javax.xml.parsers.ParserConfigurationException: Feature 
> 'http://apache.org/xml/features/xinclude' is not recognized.
>    at 
> org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(Unknown 
> Source)
>    at 
> org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:193)
>    at 
> org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:91)
>    at 
> org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)
>    at 
> org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:559)
>    at 
> org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:483)
>    at 
> org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:325)
>    at 
> org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:690)
>    at 
> org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
>    at 
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
>    at 
> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
>    at 
> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
>    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
>    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
>    ...
> ERROR StatusLogger No logging configuration   
> {noformat}
> Current retry does not cover this scenario.
> {code:java}
>            final DocumentBuilder documentBuilder = newDocumentBuilder(true);
>             Document document;
>             try {
>                 document = documentBuilder.parse(source);
>             } catch (final Exception e) {
>                 // LOG4J2-1127
>                 final Throwable throwable = Throwables.getRootCause(e);
>                 if (throwable instanceof UnsupportedOperationException) {
>                     LOGGER.warn(
>                             "The DocumentBuilder {} does not support an 
> operation: {}."
>                             + "Trying again without XInclude...",
>                             documentBuilder, e);
>                     document = newDocumentBuilder(false).parse(source);
>                 } else {
>                     throw e;
>                 }
>             }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to