diff --git a/src/main/java/org/t246osslab/easybuggy/core/listeners/InitializationListener.java b/src/main/java/org/t246osslab/easybuggy/core/listeners/InitializationListener.java index eaf39aed..673bd0e0 100644 --- a/src/main/java/org/t246osslab/easybuggy/core/listeners/InitializationListener.java +++ b/src/main/java/org/t246osslab/easybuggy/core/listeners/InitializationListener.java @@ -8,6 +8,7 @@ import javax.servlet.annotation.WebListener; import org.owasp.esapi.ESAPI; +import org.t246osslab.easybuggy.core.utils.Closer; @WebListener public class InitializationListener implements ServletContextListener { @@ -17,23 +18,29 @@ public void contextInitialized(ServletContextEvent event) { * Suppress noisy messages output by the ESAPI library. For more detail: * https://stackoverflow.com/questions/45857064/how-to-suppress-messages-output-by-esapi-library */ + PrintStream printStream = null; + OutputStream outputStream = null; + PrintStream original = System.out; try { - PrintStream original = System.out; - PrintStream out = new PrintStream(new OutputStream() { + outputStream = new OutputStream() { public void write(int b) { // Do nothing } - }); - System.setOut(out); - System.setErr(out); + }; + printStream = new PrintStream(outputStream); + System.setOut(printStream); + System.setErr(printStream); ESAPI.encoder(); - System.setOut(original); } catch (Exception e) { // Do nothing + } finally { + System.setOut(original); + Closer.close(printStream, outputStream); } } @Override public void contextDestroyed(ServletContextEvent sce) { + // Do nothing } } diff --git a/src/main/java/org/t246osslab/easybuggy/errors/ExceptionInInitializerErrorServlet.java b/src/main/java/org/t246osslab/easybuggy/errors/ExceptionInInitializerErrorServlet.java index 266e9a57..2ce09a49 100644 --- a/src/main/java/org/t246osslab/easybuggy/errors/ExceptionInInitializerErrorServlet.java +++ b/src/main/java/org/t246osslab/easybuggy/errors/ExceptionInInitializerErrorServlet.java @@ -34,4 +34,8 @@ class InitializerErrorThrower { static { LoggerFactory.getLogger(InitializerErrorThrower.class).debug("clinit" + 1 / 0); } + + private InitializerErrorThrower(){ + // this constructor is added to suppress sonar advice + } }