Buggy code:
public class AuthenticationServiceV1 { private static final Debug DEBUG = Debug . getInstance ( "amAuthREST" ) ; private static final ContentTypeHeader APPLICATION_JSON_CONTENT_TYPE = ContentTypeHeader . valueOf ( "application//json" ) ; private static final String CACHE_CONTROL_HEADER_NAME = "Cache-Control" ; private static final String NO_CACHE_CACHE_CONTROL_HEADER = "no-cache,<seq2seq4repair_space>no-store,<seq2seq4repair_space>must-revalidate" ; private static final String PRAGMA_HEADER_NAME = "Pragma" ; private static final String PRAGMA_NO_CACHE_HEADER = "no-cache" ; private static final String EXPIRES_HEADER_NAME = "Expires" ; private static final String ALWAYS_EXPIRE_HEADER = "0" ; private static final String CONTENT_TYPE_HEADER_NAME = "Content-Type" ; private static final String REALM = "realm" ; private final RestAuthenticationHandler restAuthenticationHandler ; @ Inject public AuthenticationServiceV1 ( RestAuthenticationHandler restAuthenticationHandler ) { } @ Post public Response authenticate ( @ Contextual Context context , @ Contextual Request httpRequest ) { if ( ! ( isSupportedMediaType ( httpRequest ) ) ) { if ( AuthenticationServiceV1 . DEBUG . errorEnabled ( ) ) { AuthenticationServiceV1 . DEBUG . error ( ( "AuthenticationService<seq2seq4repair_space>::<seq2seq4repair_space>Unable<seq2seq4repair_space>to<seq2seq4repair_space>handle<seq2seq4repair_space>media<seq2seq4repair_space>type<seq2seq4repair_space>request<seq2seq4repair_space>:<seq2seq4repair_space>" + ( ContentTypeHeader . valueOf ( httpRequest ) . getType ( ) ) ) ) ; } return handleErrorResponse ( httpRequest , UNSUPPORTED_MEDIA_TYPE , null ) ; } final HttpServletRequest request = getHttpServletRequest ( context ) ; final HttpServletResponse response = getHttpServletResponse ( context ) ; Form urlQueryString = getUrlQueryString ( httpRequest ) ; final String sessionUpgradeSSOTokenId = urlQueryString . getFirst ( "sessionUpgradeSSOTokenId" ) ; try { JsonValue jsonContent ; try { jsonContent = getJsonContent ( httpRequest ) ; } catch ( IOException e ) { AuthenticationServiceV1 . DEBUG . message ( "AuthenticationService.authenticate()<seq2seq4repair_space>::<seq2seq4repair_space>JSON<seq2seq4repair_space>parsing<seq2seq4repair_space>error" , e ) ; return handleErrorResponse ( httpRequest , BAD_REQUEST , e ) ; } JsonValue jsonResponse ; if ( ( jsonContent != null ) && ( ( jsonContent . size ( ) ) > 0 ) ) { jsonResponse = restAuthenticationHandler . continueAuthentication ( request , response , jsonContent , sessionUpgradeSSOTokenId ) ; } else { final String authIndexType = urlQueryString . getFirst ( "authIndexType" ) ; final String authIndexValue = urlQueryString . getFirst ( "authIndexValue" ) ; jsonResponse = restAuthenticationHandler . initiateAuthentication ( request , response , authIndexType , authIndexValue , sessionUpgradeSSOTokenId ) ; } return createResponse ( jsonResponse ) ; } catch ( RestAuthResponseException e ) { AuthenticationServiceV1 . DEBUG . message ( "AuthenticationService.authenticate()<seq2seq4repair_space>::<seq2seq4repair_space>Exception<seq2seq4repair_space>from<seq2seq4repair_space>CallbackHandler" , e ) ; return handleErrorResponse ( httpRequest , Status . valueOf ( e . getStatusCode ( ) ) , e ) ; } catch ( RestAuthException e ) { AuthenticationServiceV1 . DEBUG . message ( "AuthenticationService.authenticate()<seq2seq4repair_space>::<seq2seq4repair_space>Rest<seq2seq4repair_space>Authentication<seq2seq4repair_space>Exception" , e ) ; <START_BUG> return handleErrorResponse ( httpRequest , UNAUTHORIZED , e ) ; <END_BUG> } catch ( IOException e ) { AuthenticationServiceV1 . DEBUG . error ( "AuthenticationService.authenticate()<seq2seq4repair_space>::<seq2seq4repair_space>Internal<seq2seq4repair_space>Error" , e ) ; return handleErrorResponse ( httpRequest , INTERNAL_SERVER_ERROR , e ) ; } } private Form getUrlQueryString ( Request request ) { } private HttpServletResponse getHttpServletResponse ( Context context ) { } private boolean isSupportedMediaType ( Request request ) { } private HttpServletRequest getHttpServletRequest ( Context context ) { } private HttpServletRequest wrapRequest ( HttpServletRequest request , final RealmContext realmContext ) { } private JsonValue getJsonContent ( Request request ) throws IOException { } private Response createResponse ( final JsonValue jsonResponse ) throws IOException { } protected Response handleErrorResponse ( Request request , Status status , Exception exception ) { } protected String getLocalizedMessage ( Request request , Exception exception ) { } private String localizeMessage ( L10NMessage localizedException , Locale locale ) { } }

Fix:
return handleErrorResponse ( httpRequest , Status . valueOf ( e . getStatusCode ( ) ) , e ) ;