[AAA-34] Stop creating static exception instances Created: 01/Jun/15  Updated: 21/Mar/19  Resolved: 21/Jul/15

Status: Resolved
Project: aaa
Component/s: General
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Devin Avery Assignee: Ryan Goulding
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 3519

 Description   

I found that the TokenAuthFilter.java class creates a static exception:

private static final WebApplicationException UNAVAILABLE_EX = new WebApplicationException(
Response.status(Status.SERVICE_UNAVAILABLE)
.type(MediaType.APPLICATION_JSON)
.entity("

{\"error\":\"Authentication service unavailable\"}

")
.build());

It seems that the intent was to deduplicate the amount of code written inline with statics. While this is fine for a static Response message, by creating the exception object here and not inline you get incorrect trace information when the exception is thrown.

We should change this so that the exception is not created here, but just the response (i.e. the response is static).

Then when we throw the exception in the constructor we should create the new WebApplicationException object. This way the exception will have the proper trace and you get the reusable response.

While this is a single example, there are other cases in this same file and other files that should be reviewed and fixed as well.

File: https://github.com/opendaylight/aaa/blob/master/aaa-authn-sts/src/main/java/org/opendaylight/aaa/sts/TokenAuthFilter.java

NOTE: If we are intentionally doing this for some reason then the code should be commented to describe why.



 Comments   
Comment by Ryan Goulding [ 20/Jul/15 ]

https://git.opendaylight.org/gerrit/#/c/23698/

Generated at Wed Feb 07 19:08:27 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.