How to disable accessExternalDTD and entityExpansionLimit warnings with logback

后端 未结 4 780
迷失自我
迷失自我 2021-01-31 17:03

I\'m using logback with groovy and get lots of warnings showing up when parsing xml. I am aware of the bug in JDK1.7_u45 that is causing this.

Warning:  org.apa         


        
4条回答
  •  遇见更好的自我
    2021-01-31 17:33

    This is a known bug in the JRE that reports this as an warning. See bug reports here and here

    The issue happens only when you have xerces jar in your classpath, the xerces implementation does not recognize the property and throws an exception on org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.setProperty() which results in a warning log (to System.err) from the com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parse()

    The easy (if possible) solution is remove xerces jar from your classpath.

    Your log filter does not work since the error is never sent to slf4j. Which kind of suggests a convoluted way of fixing the issue - redirect System.err to slf4j and then use a logging filter on it.

    Sample code to reproduce the issue (based on the issue report):

    import java.io.IOException;
    import java.net.URL;
    
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.stream.StreamSource;
    
    public class XercesTest {
        public static void main(String[] args) throws IOException, TransformerConfigurationException {
            TransformerFactory tf = TransformerFactory.newInstance();
            URL xsl = MainClass.class.getResource("build.xsl");
            StreamSource stylesheetSource = new StreamSource(
                xsl.openStream(), xsl.toExternalForm());
            tf.newTransformer(stylesheetSource);
        }
    }
    

    build.xsl

    
    
        
            
        
    
    

    And maven dependency:

    
        xerces
        xercesImpl
        2.11.0
    
    

提交回复
热议问题