diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-07-28 16:36:17 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-07-28 16:36:17 -0400 |
| commit | b1317e5e62bb044cd8a676cb3fc2da86e9922caf (patch) | |
| tree | 2c743633784df8ad4ab4dc76846b363023164b37 /BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java | |
| parent | a100f2a0d71f37320fe0f73be0d6d65094b60eb0 (diff) | |
Added debugging aid for finding single instantiation violations.
Also, fixed a single instantiation violation into BoundLazyPair
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java index 016f492..989f1a5 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java +++ b/BJC-Utils2/src/main/java/bjc/utils/data/SingleSupplier.java @@ -9,6 +9,10 @@ public class SingleSupplier<T> implements Supplier<T> { private long id; + // This is bad practice, but I want to know where the single + // instantiation was, in case of duplicate initiations + private Exception instSite; + private static long nextID = 0; public SingleSupplier(Supplier<T> supp) { @@ -22,13 +26,25 @@ public class SingleSupplier<T> implements Supplier<T> { @Override public T get() { if (gotten == true) { - throw new IllegalStateException( + IllegalStateException isex = new IllegalStateException( "Attempted to get value more than once" - + " from single supplier #" + id); + + " from single supplier #" + id + + ". Previous instantiation below."); + + isex.initCause(instSite); + + throw isex; } gotten = true; + try { + throw new IllegalStateException( + "Previous instantiation here."); + } catch (IllegalStateException isex) { + instSite = isex; + } + return source.get(); } } |
