From 24f258848c67500d347f9cce051f27aecda48f97 Mon Sep 17 00:00:00 2001 From: shaiktaj Date: Thu, 25 May 2017 11:04:30 -0500 Subject: [PATCH] Updated ThreadSafeLazyLoadedivoryTower Added null check in private constructor to prevent instantiating by Reflection call --- .../iluwatar/singleton/ThreadSafeLazyLoadedIvoryTower.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/singleton/src/main/java/com/iluwatar/singleton/ThreadSafeLazyLoadedIvoryTower.java b/singleton/src/main/java/com/iluwatar/singleton/ThreadSafeLazyLoadedIvoryTower.java index 0b1b51b23..68f190d46 100644 --- a/singleton/src/main/java/com/iluwatar/singleton/ThreadSafeLazyLoadedIvoryTower.java +++ b/singleton/src/main/java/com/iluwatar/singleton/ThreadSafeLazyLoadedIvoryTower.java @@ -33,7 +33,12 @@ public final class ThreadSafeLazyLoadedIvoryTower { private static ThreadSafeLazyLoadedIvoryTower instance; - private ThreadSafeLazyLoadedIvoryTower() {} + private ThreadSafeLazyLoadedIvoryTower() { + // to prevent instantiating by Reflection call + if (instance != null) { + throw new IllegalStateException("Already initialized."); + } + } /** * The instance gets created only when it is called for first time. Lazy-loading