-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix problem with ErrorCode initialization wrt config access #1380
Conversation
@@ -207,17 +207,6 @@ public enum ErrorCode { | |||
TABLE_COLUMN_UNKNOWN("Column unknown"); | |||
|
|||
private final String message; | |||
private final boolean extendError = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Access from constructor of EVERY enum constant is pretty wasteful to begin with, but more importantly caused odd initialization failure from any Integration Test that tried to refer to ErrorCode
enums.
Hence moved to be done lazily when needed, not eagerly before everything else.
@@ -241,7 +230,7 @@ public JsonApiException toApiException(Throwable cause, String format, Object... | |||
} | |||
|
|||
private String getErrorMessage(String format, Object... args) { | |||
if (extendError) { | |||
if (ExtendError.enabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First access to getErrorMessage()
of any ErrorCode
instance will load ExtendError
helper class, which will get configuration settings. This is properly synchronized as guaranteed by JVM classloading, and all further access is via properly initialized singleton.
* loading calls. | ||
*/ | ||
static class ExtendError { | ||
private static final ExtendError instance = new ExtendError(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of private static instance and accessor, could have exposed this as public
. But looks to me slightly cleaner from caller this way.
What this PR does:
Fixes a problem with
ErrorCode
initialization occurring during IT runs; allows use of ErrorCode enum values again.Which issue(s) this PR fixes:
N/A
Checklist