Created
June 6, 2024 22:15
-
-
Save kardolus/2452ceeb563790c3f4874658de670600 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public synchronized void init( ServletConfig servletConfig ) throws ServletException { | |
GatewayConfig gatewayConfig = (GatewayConfig) servletConfig.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE); | |
isErrorMessageSanitizationEnabled = gatewayConfig.isErrorMessageSanitizationEnabled(); | |
errorMessageSanitizationPattern = gatewayConfig.getErrorMessageSanitizationPattern(); | |
try { | |
if( filter == null ) { | |
filter = createFilter( servletConfig ); | |
} | |
filterConfig = new FilterConfigAdapter( servletConfig ); | |
if( filter != null ) { | |
filter.init( filterConfig ); | |
} | |
} catch( ServletException | RuntimeException e ) { | |
throw logAndSanitizeException(e); | |
} | |
} | |
// Compilation fails: java: unreported exception java.lang.Exception; must be caught or declared to be thrown | |
private <T extends Exception> T logAndSanitizeException(Exception e) { | |
LOG.failedToExecuteFilter(e); | |
return (T) sanitizeException(e); | |
} | |
// Compiles but tests fail. IntelliJ warns us that we don't have to declare that we throw T | |
private <T extends Exception> T logAndSanitizeException(Exception e) throws T { | |
LOG.failedToExecuteFilter(e); | |
return (T) sanitizeException(e); | |
} | |
// this works | |
private <T extends Exception> T logAndSanitizeException(Exception e) throws T { | |
LOG.failedToExecuteFilter(e); | |
throw (T) sanitizeException(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment