You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2017/03/13 16:36:37 UTC
asterixdb git commit: ErrorCode Map Initialization Needs To Be Thread
Safe
Repository: asterixdb
Updated Branches:
refs/heads/master 343cd457d -> b1575d8c0
ErrorCode Map Initialization Needs To Be Thread Safe
Reworked deferred initialization of error message map to be thread safe
Change-Id: I78c0df172038bb1a97297837ff7c82b2727f8556
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1571
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <ba...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/b1575d8c
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/b1575d8c
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/b1575d8c
Branch: refs/heads/master
Commit: b1575d8c0adb3253851f9a110644e4a949e575b4
Parents: 343cd45
Author: Michael Blow <mb...@apache.org>
Authored: Sun Mar 12 16:21:10 2017 -0400
Committer: Michael Blow <mb...@apache.org>
Committed: Mon Mar 13 09:35:42 2017 -0700
----------------------------------------------------------------------
.../asterix/common/exceptions/ErrorCode.java | 18 ++++++++++------
.../hyracks/api/exceptions/ErrorCode.java | 22 +++++++++++++-------
2 files changed, 26 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/b1575d8c/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index 517e243..8f859c7 100644
--- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -165,21 +165,27 @@ public class ErrorCode {
public static final int UTIL_LOCAL_FILE_SYSTEM_UTILS_PATH_NOT_FOUND = 3077;
public static final int UTIL_HDFS_UTILS_CANNOT_OBTAIN_HDFS_SCHEDULER = 3078;
- // Loads the map that maps error codes to error message templates.
- private static Map<Integer, String> errorMessageMap = null;
-
private ErrorCode() {
}
- public static String getErrorMessage(int errorCode) {
- if (errorMessageMap == null) {
+ private static class Holder {
+ private static final Map<Integer, String> errorMessageMap;
+
+ static {
+ // Loads the map that maps error codes to error message templates.
try (InputStream resourceStream = ErrorCode.class.getClassLoader().getResourceAsStream(RESOURCE_PATH)) {
errorMessageMap = ErrorMessageUtil.loadErrorMap(resourceStream);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
- String msg = errorMessageMap.get(errorCode);
+
+ private Holder() {
+ }
+ }
+
+ public static String getErrorMessage(int errorCode) {
+ String msg = Holder.errorMessageMap.get(errorCode);
if (msg == null) {
throw new IllegalStateException("Undefined error code: " + errorCode);
}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/b1575d8c/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java
index 333b1df..401103b 100644
--- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java
+++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java
@@ -64,21 +64,27 @@ public class ErrorCode {
// Compilation error codes.
public static final int RULECOLLECTION_NOT_INSTANCE_OF_LIST = 10001;
- // Loads the map that maps error codes to error message templates.
- private static Map<Integer, String> errorMessageMap = null;
+ private static class Holder {
+ private static final Map<Integer, String> errorMessageMap;
- private ErrorCode() {
- }
-
- public static String getErrorMessage(int errorCode) {
- if (errorMessageMap == null) {
+ static {
+ // Loads the map that maps error codes to error message templates.
try (InputStream resourceStream = ErrorCode.class.getClassLoader().getResourceAsStream(RESOURCE_PATH)) {
errorMessageMap = ErrorMessageUtil.loadErrorMap(resourceStream);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
- String msg = errorMessageMap.get(errorCode);
+
+ private Holder() {
+ }
+ }
+
+ private ErrorCode() {
+ }
+
+ public static String getErrorMessage(int errorCode) {
+ String msg = Holder.errorMessageMap.get(errorCode);
if (msg == null) {
throw new IllegalStateException("Undefined error code: " + errorCode);
}