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:
Dominik Stadler 2016-12-26 19:51:42 +00:00
parent fce89b2c5c
commit 219b0ab691
1 changed files with 6 additions and 1 deletions

View File

@ -20,6 +20,7 @@ package org.apache.poi.util;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
import javax.xml.XMLConstants;
import javax.xml.parsers.ParserConfigurationException;
@ -36,6 +37,7 @@ import org.xml.sax.XMLReader;
*/
public final class SAXHelper {
private static POILogger logger = POILogFactory.getLogger(SAXHelper.class);
private static long lastLog = 0;
private SAXHelper() {}
@ -89,7 +91,10 @@ public final class SAXHelper {
// Stop once one can be setup without error
return;
} 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);
}
}
}
}