Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
k-tamura committed Aug 26, 2017
1 parent 5ee717c commit d42e34f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit d42e34f

Please sign in to comment.