Skip to content
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

Merged
merged 1 commit into from
Aug 30, 2024

Conversation

tatu-at-datastax
Copy link
Contributor

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

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

@tatu-at-datastax tatu-at-datastax requested a review from a team as a code owner August 29, 2024 23:56
@@ -207,17 +207,6 @@ public enum ErrorCode {
TABLE_COLUMN_UNKNOWN("Column unknown");

private final String message;
private final boolean extendError =
Copy link
Contributor Author

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()) {
Copy link
Contributor Author

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();
Copy link
Contributor Author

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.

@tatu-at-datastax tatu-at-datastax merged commit 7bbdb88 into main Aug 30, 2024
3 checks passed
@tatu-at-datastax tatu-at-datastax deleted the tatu/fix-error-code-init branch August 30, 2024 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants