From eaf2bee38738a439a7c6647bb909e3f9228c39e2 Mon Sep 17 00:00:00 2001 From: Jessie Zhang Date: Thu, 29 Aug 2024 14:38:15 -0700 Subject: [PATCH] Revert "Fix SpotBug issues" This reverts commit 8f5f3aaa17d76d3a9ce01e3c079918df55135b9b. --- aws-organizations-account/pom.xml | 3 --- .../organizations/account/BaseHandlerStd.java | 4 ++-- .../organizations/account/CallbackContext.java | 15 +-------------- aws-organizations-organization/pom.xml | 3 --- .../organization/BaseHandlerStd.java | 4 ++-- .../organization/CallbackContext.java | 13 +------------ aws-organizations-organizationalunit/pom.xml | 3 --- .../organizationalunit/BaseHandlerStd.java | 4 ++-- .../organizationalunit/CallbackContext.java | 14 +------------- aws-organizations-policy/pom.xml | 3 --- .../organizations/policy/BaseHandlerStd.java | 4 ++-- .../organizations/policy/CallbackContext.java | 15 +-------------- aws-organizations-resourcepolicy/pom.xml | 3 --- .../resourcepolicy/BaseHandlerStd.java | 4 ++-- .../resourcepolicy/CallbackContext.java | 14 +------------- 15 files changed, 15 insertions(+), 91 deletions(-) diff --git a/aws-organizations-account/pom.xml b/aws-organizations-account/pom.xml index 46b01a2..a84e0ec 100644 --- a/aws-organizations-account/pom.xml +++ b/aws-organizations-account/pom.xml @@ -175,9 +175,6 @@ org.apache.maven.plugins maven-surefire-plugin 3.0.0-M3 - - --add-opens java.base/java.util=ALL-UNNAMED - org.jacoco diff --git a/aws-organizations-account/src/main/java/software/amazon/organizations/account/BaseHandlerStd.java b/aws-organizations-account/src/main/java/software/amazon/organizations/account/BaseHandlerStd.java index 785be63..2f6923c 100644 --- a/aws-organizations-account/src/main/java/software/amazon/organizations/account/BaseHandlerStd.java +++ b/aws-organizations-account/src/main/java/software/amazon/organizations/account/BaseHandlerStd.java @@ -43,7 +43,6 @@ public abstract class BaseHandlerStd extends BaseHandler { protected static final String ACCOUNT_CREATION_STATUS_SUCCEEDED = "SUCCEEDED"; protected static final String ACCOUNT_CREATION_STATUS_FAILED = "FAILED"; // ExponentialBackoffJitter Constants - private static final Random RANDOM = new Random(); protected static final double RANDOMIZATION_FACTOR = 0.5; protected static final double RANDOMIZATION_FACTOR_FOR_DESCRIBE_CREATE_ACCOUNT_STATUS = 0.2; protected static final int BASE_DELAY = 15; // in second @@ -163,8 +162,9 @@ public ProgressEvent handleErrorTranslation( } public final int computeDelayBeforeNextRetry(int retryAttempt, int baseDelay, double randomizationFactor) { + Random random = new Random(); int exponentialBackoff = (int) Math.pow(2, retryAttempt) * baseDelay; - int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * randomizationFactor)); + int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * randomizationFactor)); return exponentialBackoff + jitter; } diff --git a/aws-organizations-account/src/main/java/software/amazon/organizations/account/CallbackContext.java b/aws-organizations-account/src/main/java/software/amazon/organizations/account/CallbackContext.java index a5f8444..8e7d3a1 100644 --- a/aws-organizations-account/src/main/java/software/amazon/organizations/account/CallbackContext.java +++ b/aws-organizations-account/src/main/java/software/amazon/organizations/account/CallbackContext.java @@ -8,30 +8,17 @@ @lombok.Getter @lombok.Setter @lombok.ToString -@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap") +@lombok.EqualsAndHashCode(callSuper = true) public class CallbackContext extends StdCallbackContext { private Map actionToRetryAttemptMap = new HashMap<>(); - - // Manually implement the setter with a defensive copy - public void setActionToRetryAttemptMap(Map actionToRetryAttemptMap) { - this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap); - } - - // Manually implement the getter with a defensive copy - public Map getActionToRetryAttemptMap() { - return new HashMap<>(actionToRetryAttemptMap); - } - public int getCurrentRetryAttempt(final AccountConstants.Action actionName, final AccountConstants.Handler handlerName) { String key = actionName.toString() + handlerName.toString(); return this.actionToRetryAttemptMap.getOrDefault(key, 0); } - public void setCurrentRetryAttempt(final AccountConstants.Action actionName, final AccountConstants.Handler handlerName) { String key = actionName.toString() + handlerName.toString(); this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName)+1); } - // used in CREATE handler private boolean isAccountCreated = false; private String createAccountRequestId; diff --git a/aws-organizations-organization/pom.xml b/aws-organizations-organization/pom.xml index 23a19c3..2aaf0e3 100644 --- a/aws-organizations-organization/pom.xml +++ b/aws-organizations-organization/pom.xml @@ -174,9 +174,6 @@ org.apache.maven.plugins maven-surefire-plugin 3.0.0-M3 - - --add-opens java.base/java.util=ALL-UNNAMED - org.jacoco diff --git a/aws-organizations-organization/src/main/java/software/amazon/organizations/organization/BaseHandlerStd.java b/aws-organizations-organization/src/main/java/software/amazon/organizations/organization/BaseHandlerStd.java index bae44ed..43210bd 100644 --- a/aws-organizations-organization/src/main/java/software/amazon/organizations/organization/BaseHandlerStd.java +++ b/aws-organizations-organization/src/main/java/software/amazon/organizations/organization/BaseHandlerStd.java @@ -26,7 +26,6 @@ import java.util.Random; public abstract class BaseHandlerStd extends BaseHandler { - private static final Random RANDOM = new Random(); private static final double RANDOMIZATION_FACTOR = 0.5; private static final int BASE_DELAY = 15; //in seconds private static final int MAX_RETRY_ATTEMPT_FOR_RETRIABLE_EXCEPTION = 2; @@ -126,8 +125,9 @@ && isRetriableException(e)) { } public final int computeDelayBeforeNextRetry(int retryAttempt) { + Random random = new Random(); int exponentialBackoff = (int) Math.pow(2, retryAttempt) * BASE_DELAY; - int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR)); + int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR)); return exponentialBackoff + jitter; } diff --git a/aws-organizations-organization/src/main/java/software/amazon/organizations/organization/CallbackContext.java b/aws-organizations-organization/src/main/java/software/amazon/organizations/organization/CallbackContext.java index 86da7bd..6d6ea8d 100644 --- a/aws-organizations-organization/src/main/java/software/amazon/organizations/organization/CallbackContext.java +++ b/aws-organizations-organization/src/main/java/software/amazon/organizations/organization/CallbackContext.java @@ -8,20 +8,10 @@ @lombok.Getter @lombok.Setter @lombok.ToString -@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap") +@lombok.EqualsAndHashCode(callSuper = true) public class CallbackContext extends StdCallbackContext { private Map actionToRetryAttemptMap = new HashMap<>(); - // Manually implement the setter with a defensive copy - public void setActionToRetryAttemptMap(Map actionToRetryAttemptMap) { - this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap); - } - - // Manually implement the getter with a defensive copy - public Map getActionToRetryAttemptMap() { - return new HashMap<>(actionToRetryAttemptMap); - } - // Used to set Propagation Delay in the CreateHandler call chain. public boolean propagationDelay = false; // used in CREATE handler re-invoking @@ -31,7 +21,6 @@ public int getCurrentRetryAttempt(final OrganizationConstants.Action actionName, String key = actionName.toString() + handlerName.toString(); return this.actionToRetryAttemptMap.getOrDefault(key, 0); } - public void setCurrentRetryAttempt(final OrganizationConstants.Action actionName, final OrganizationConstants.Handler handlerName) { String key = actionName.toString() + handlerName.toString(); this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName) + 1); diff --git a/aws-organizations-organizationalunit/pom.xml b/aws-organizations-organizationalunit/pom.xml index b11f863..388f06f 100644 --- a/aws-organizations-organizationalunit/pom.xml +++ b/aws-organizations-organizationalunit/pom.xml @@ -175,9 +175,6 @@ org.apache.maven.plugins maven-surefire-plugin 3.0.0-M3 - - --add-opens java.base/java.util=ALL-UNNAMED - org.jacoco diff --git a/aws-organizations-organizationalunit/src/main/java/software/amazon/organizations/organizationalunit/BaseHandlerStd.java b/aws-organizations-organizationalunit/src/main/java/software/amazon/organizations/organizationalunit/BaseHandlerStd.java index b375758..4309e25 100644 --- a/aws-organizations-organizationalunit/src/main/java/software/amazon/organizations/organizationalunit/BaseHandlerStd.java +++ b/aws-organizations-organizationalunit/src/main/java/software/amazon/organizations/organizationalunit/BaseHandlerStd.java @@ -32,7 +32,6 @@ public abstract class BaseHandlerStd extends BaseHandler { // ExponentialBackoffJitter Constants - private static final Random RANDOM = new Random(); private static final double RANDOMIZATION_FACTOR = 0.5; private static final int BASE_DELAY = 15; // in seconds private static final int MAX_RETRY_ATTEMPT_FOR_RETRIABLE_EXCEPTION = 2; @@ -123,8 +122,9 @@ && isRetriableException(e)) { } public final int computeDelayBeforeNextRetry(int retryAttempt) { + Random random = new Random(); int exponentialBackoff = (int) Math.pow(2, retryAttempt) * BASE_DELAY; - int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR)); + int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR)); return exponentialBackoff + jitter; } diff --git a/aws-organizations-organizationalunit/src/main/java/software/amazon/organizations/organizationalunit/CallbackContext.java b/aws-organizations-organizationalunit/src/main/java/software/amazon/organizations/organizationalunit/CallbackContext.java index ed32882..61fca23 100644 --- a/aws-organizations-organizationalunit/src/main/java/software/amazon/organizations/organizationalunit/CallbackContext.java +++ b/aws-organizations-organizationalunit/src/main/java/software/amazon/organizations/organizationalunit/CallbackContext.java @@ -8,25 +8,13 @@ @lombok.Getter @lombok.Setter @lombok.ToString -@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap") +@lombok.EqualsAndHashCode(callSuper = true) public class CallbackContext extends StdCallbackContext { private Map actionToRetryAttemptMap = new HashMap<>(); - - // Manually implement the setter with a defensive copy - public void setActionToRetryAttemptMap(Map actionToRetryAttemptMap) { - this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap); - } - - // Manually implement the getter with a defensive copy - public Map getActionToRetryAttemptMap() { - return new HashMap<>(actionToRetryAttemptMap); - } - public int getCurrentRetryAttempt(final Constants.Action actionName, final Constants.Handler handlerName) { String key = actionName.toString() + handlerName.toString(); return this.actionToRetryAttemptMap.getOrDefault(key, 0); } - public void setCurrentRetryAttempt(final Constants.Action actionName, final Constants.Handler handlerName) { String key = actionName.toString() + handlerName.toString(); this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName)+1); diff --git a/aws-organizations-policy/pom.xml b/aws-organizations-policy/pom.xml index d9a7046..c8ad925 100644 --- a/aws-organizations-policy/pom.xml +++ b/aws-organizations-policy/pom.xml @@ -182,9 +182,6 @@ org.apache.maven.plugins maven-surefire-plugin 3.0.0-M3 - - --add-opens java.base/java.util=ALL-UNNAMED - org.jacoco diff --git a/aws-organizations-policy/src/main/java/software/amazon/organizations/policy/BaseHandlerStd.java b/aws-organizations-policy/src/main/java/software/amazon/organizations/policy/BaseHandlerStd.java index 252fb45..8a11b3f 100644 --- a/aws-organizations-policy/src/main/java/software/amazon/organizations/policy/BaseHandlerStd.java +++ b/aws-organizations-policy/src/main/java/software/amazon/organizations/policy/BaseHandlerStd.java @@ -36,7 +36,6 @@ public abstract class BaseHandlerStd extends BaseHandler { // ExponentialBackoffJitter Constants - private static final Random RANDOM = new Random(); private static final double RANDOMIZATION_FACTOR = 0.5; private static final int BASE_DELAY = 15; // in seconds private static final int MAX_RETRY_ATTEMPT_FOR_RETRIABLE_EXCEPTION = 2; @@ -120,8 +119,9 @@ && isRetriableException(e)) { } public final int computeDelayBeforeNextRetry(int retryAttempt) { + Random random = new Random(); int exponentialBackoff = (int) Math.pow(2, retryAttempt) * BASE_DELAY; - int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR)); + int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR)); return exponentialBackoff + jitter; } diff --git a/aws-organizations-policy/src/main/java/software/amazon/organizations/policy/CallbackContext.java b/aws-organizations-policy/src/main/java/software/amazon/organizations/policy/CallbackContext.java index e6d228e..49b3c3f 100644 --- a/aws-organizations-policy/src/main/java/software/amazon/organizations/policy/CallbackContext.java +++ b/aws-organizations-policy/src/main/java/software/amazon/organizations/policy/CallbackContext.java @@ -8,30 +8,17 @@ @lombok.Getter @lombok.Setter @lombok.ToString -@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap") +@lombok.EqualsAndHashCode(callSuper = true) public class CallbackContext extends StdCallbackContext { private Map actionToRetryAttemptMap = new HashMap<>(); - - // Manually implement the setter with a defensive copy - public void setActionToRetryAttemptMap(Map actionToRetryAttemptMap) { - this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap); - } - - // Manually implement the getter with a defensive copy - public Map getActionToRetryAttemptMap() { - return new HashMap<>(actionToRetryAttemptMap); - } - public int getCurrentRetryAttempt(final PolicyConstants.Action actionName, final PolicyConstants.Handler handlerName) { String key = actionName.toString() + handlerName.toString(); return this.actionToRetryAttemptMap.getOrDefault(key, 0); } - public void setCurrentRetryAttempt(final PolicyConstants.Action actionName, final PolicyConstants.Handler handlerName) { String key = actionName.toString() + handlerName.toString(); this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName)+1); } - // used in CREATE handler re-invoking private boolean isPolicyCreated = false; // used in DELETE handler re-invoking diff --git a/aws-organizations-resourcepolicy/pom.xml b/aws-organizations-resourcepolicy/pom.xml index 2321d0c..63dcf8e 100644 --- a/aws-organizations-resourcepolicy/pom.xml +++ b/aws-organizations-resourcepolicy/pom.xml @@ -175,9 +175,6 @@ org.apache.maven.plugins maven-surefire-plugin 3.0.0-M3 - - --add-opens java.base/java.util=ALL-UNNAMED - org.jacoco diff --git a/aws-organizations-resourcepolicy/src/main/java/software/amazon/organizations/resourcepolicy/BaseHandlerStd.java b/aws-organizations-resourcepolicy/src/main/java/software/amazon/organizations/resourcepolicy/BaseHandlerStd.java index d765d70..8039e8c 100644 --- a/aws-organizations-resourcepolicy/src/main/java/software/amazon/organizations/resourcepolicy/BaseHandlerStd.java +++ b/aws-organizations-resourcepolicy/src/main/java/software/amazon/organizations/resourcepolicy/BaseHandlerStd.java @@ -27,7 +27,6 @@ public abstract class BaseHandlerStd extends BaseHandler { // ExponentialBackoffJitter Constants - private static final Random RANDOM = new Random(); private static final double RANDOMIZATION_FACTOR = 0.5; private static final int BASE_DELAY = 15; // in seconds private static final int MAX_RETRY_ATTEMPT_FOR_RETRIABLE_EXCEPTION = 2; @@ -115,8 +114,9 @@ && isRetriableException(e)) { } public final int computeDelayBeforeNextRetry(int retryAttempt) { + Random random = new Random(); int exponentialBackoff = (int) Math.pow(2, retryAttempt) * BASE_DELAY; - int jitter = RANDOM.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR)); + int jitter = random.nextInt((int) Math.ceil(exponentialBackoff * RANDOMIZATION_FACTOR)); return exponentialBackoff + jitter; } diff --git a/aws-organizations-resourcepolicy/src/main/java/software/amazon/organizations/resourcepolicy/CallbackContext.java b/aws-organizations-resourcepolicy/src/main/java/software/amazon/organizations/resourcepolicy/CallbackContext.java index 2958815..5737ddf 100644 --- a/aws-organizations-resourcepolicy/src/main/java/software/amazon/organizations/resourcepolicy/CallbackContext.java +++ b/aws-organizations-resourcepolicy/src/main/java/software/amazon/organizations/resourcepolicy/CallbackContext.java @@ -8,25 +8,13 @@ @lombok.Getter @lombok.Setter @lombok.ToString -@lombok.EqualsAndHashCode(callSuper = true, exclude = "actionToRetryAttemptMap") +@lombok.EqualsAndHashCode(callSuper = true) public class CallbackContext extends StdCallbackContext { private Map actionToRetryAttemptMap = new HashMap<>(); - - // Manually implement the setter with a defensive copy - public void setActionToRetryAttemptMap(Map actionToRetryAttemptMap) { - this.actionToRetryAttemptMap = new HashMap<>(actionToRetryAttemptMap); - } - - // Manually implement the getter with a defensive copy - public Map getActionToRetryAttemptMap() { - return new HashMap<>(actionToRetryAttemptMap); - } - public int getCurrentRetryAttempt(final ResourcePolicyConstants.Action actionName, final ResourcePolicyConstants.Handler handlerName) { String key = actionName.toString() + handlerName.toString(); return this.actionToRetryAttemptMap.getOrDefault(key, 0); } - public void setCurrentRetryAttempt(final ResourcePolicyConstants.Action actionName, final ResourcePolicyConstants.Handler handlerName) { String key = actionName.toString() + handlerName.toString(); this.actionToRetryAttemptMap.put(key, getCurrentRetryAttempt(actionName, handlerName)+1);