-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,17 +207,6 @@ public enum ErrorCode { | |
TABLE_COLUMN_UNKNOWN("Column unknown"); | ||
|
||
private final String message; | ||
private final boolean extendError = | ||
ApiConstants.isOffline() | ||
? new SmallRyeConfigBuilder() | ||
.withMapping(OperationsConfig.class) | ||
.build() | ||
.getConfigMapping(OperationsConfig.class) | ||
.extendError() | ||
: ConfigProvider.getConfig() | ||
.unwrap(SmallRyeConfig.class) | ||
.getConfigMapping(OperationsConfig.class) | ||
.extendError(); | ||
|
||
ErrorCode(String message) { | ||
this.message = message; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. First access to |
||
return String.format(format, args); | ||
} | ||
return message + ": " + String.format(format, args); | ||
|
@@ -254,4 +243,33 @@ public JsonApiException toApiException() { | |
public JsonApiException toApiException(Response.Status httpStatus) { | ||
return new JsonApiException(this, message, null, httpStatus); | ||
} | ||
|
||
/** | ||
* Helper class to cache loading of settings from the configuration. This is used to avoid having | ||
* to access Config during Enum class initialization. It will also prevent repeated configuration | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more. Instead of private static instance and accessor, could have exposed this as |
||
|
||
private final boolean enabled; | ||
|
||
public ExtendError() { | ||
enabled = | ||
ApiConstants.isOffline() | ||
? new SmallRyeConfigBuilder() | ||
.withMapping(OperationsConfig.class) | ||
.build() | ||
.getConfigMapping(OperationsConfig.class) | ||
.extendError() | ||
: ConfigProvider.getConfig() | ||
.unwrap(SmallRyeConfig.class) | ||
.getConfigMapping(OperationsConfig.class) | ||
.extendError(); | ||
} | ||
|
||
public static boolean enabled() { | ||
return instance.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.
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.