From 6d93cbcd677c2675cfccc52bb69ea0046d821fc4 Mon Sep 17 00:00:00 2001 From: manusa Date: Thu, 18 Feb 2021 11:07:41 +0100 Subject: [PATCH] fix: Replace double-checked locking idiom with initialization-on-demand holder idiom - https://rules.sonarsource.com/java/tag/multi-threading/RSPEC-2168 - https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom --- .../client/internal/readiness/Readiness.java | 11 ++++------- .../client/internal/readiness/OpenShiftReadiness.java | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/internal/readiness/Readiness.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/internal/readiness/Readiness.java index 69708bbdc94..9a6b52331f2 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/internal/readiness/Readiness.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/internal/readiness/Readiness.java @@ -49,15 +49,12 @@ public class Readiness { protected static final String READINESS_APPLICABLE_RESOURCES = "Node, Deployment, ReplicaSet, StatefulSet, Pod, ReplicationController"; - private static Readiness instance; + private static class ReadinessHolder { + public static final Readiness INSTANCE = new Readiness(); + } public static Readiness getInstance() { - if (instance == null) { - synchronized (Readiness.class) { - instance = new Readiness(); - } - } - return instance; + return ReadinessHolder.INSTANCE; } /** diff --git a/openshift-client/src/main/java/io/fabric8/openshift/client/internal/readiness/OpenShiftReadiness.java b/openshift-client/src/main/java/io/fabric8/openshift/client/internal/readiness/OpenShiftReadiness.java index 03976faea61..a0e7db59c8e 100644 --- a/openshift-client/src/main/java/io/fabric8/openshift/client/internal/readiness/OpenShiftReadiness.java +++ b/openshift-client/src/main/java/io/fabric8/openshift/client/internal/readiness/OpenShiftReadiness.java @@ -27,15 +27,12 @@ public class OpenShiftReadiness extends Readiness { private static final String OPENSHIFT_READINESS_APPLICABLE_RESOURCES = READINESS_APPLICABLE_RESOURCES + ", " + "DeploymentConfig"; - private static OpenShiftReadiness instance; + private static class OpenShiftReadinessHolder { + public static final OpenShiftReadiness INSTANCE = new OpenShiftReadiness(); + } public static OpenShiftReadiness getInstance() { - if (instance == null) { - synchronized (OpenShiftReadiness.class) { - instance = new OpenShiftReadiness(); - } - } - return instance; + return OpenShiftReadinessHolder.INSTANCE; } @Override