Add some throttling to the log for failed SAXHelper features to not spam the log on JDK 9 with restricted reflection

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1776067 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
centic 2016-12-26 19:51:42 +00:00
parent 0b17d4def9
commit 25b22afebf

View File

@ -20,6 +20,7 @@ package org.apache.poi.util;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@ -36,6 +37,7 @@ import org.xml.sax.XMLReader;
*/ */
public final class SAXHelper { public final class SAXHelper {
private static POILogger logger = POILogFactory.getLogger(SAXHelper.class); private static POILogger logger = POILogFactory.getLogger(SAXHelper.class);
private static long lastLog = 0;
private SAXHelper() {} private SAXHelper() {}
@ -89,7 +91,10 @@ public final class SAXHelper {
// Stop once one can be setup without error // Stop once one can be setup without error
return; return;
} catch (Throwable e) { // NOSONAR - also catch things like NoClassDefError here } catch (Throwable e) { // NOSONAR - also catch things like NoClassDefError here
logger.log(POILogger.WARN, "SAX Security Manager could not be setup", e); // throttle the log somewhat as it can spam the log otherwise
if(System.currentTimeMillis() > lastLog + TimeUnit.MINUTES.toMillis(5)) {
logger.log(POILogger.WARN, "SAX Security Manager could not be setup [log suppressed for 5 minutes]", e);
}
} }
} }
} }