From 7994e02c718fe780fd241f63b2759c629ef6b6bb Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Fri, 4 Jul 2014 22:35:29 -0400 Subject: [PATCH] Add identity hash codes to some substitution trace messages Otherwise you can't tell how it works since replacements and memoization are done by identity. --- .../src/main/java/com/typesafe/config/impl/MemoKey.java | 2 +- .../java/com/typesafe/config/impl/ResolveContext.java | 3 ++- .../java/com/typesafe/config/impl/ResolveSource.java | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config/src/main/java/com/typesafe/config/impl/MemoKey.java b/config/src/main/java/com/typesafe/config/impl/MemoKey.java index c9c73e14..cd843dad 100644 --- a/config/src/main/java/com/typesafe/config/impl/MemoKey.java +++ b/config/src/main/java/com/typesafe/config/impl/MemoKey.java @@ -39,6 +39,6 @@ final class MemoKey { @Override public final String toString() { - return "MemoKey(" + value + "," + restrictToChildOrNull + ")"; + return "MemoKey(" + value + "@" + System.identityHashCode(value) + "," + restrictToChildOrNull + ")"; } } diff --git a/config/src/main/java/com/typesafe/config/impl/ResolveContext.java b/config/src/main/java/com/typesafe/config/impl/ResolveContext.java index a6f9a469..42e54d72 100644 --- a/config/src/main/java/com/typesafe/config/impl/ResolveContext.java +++ b/config/src/main/java/com/typesafe/config/impl/ResolveContext.java @@ -127,7 +127,8 @@ final class ResolveContext { return cached; } else { if (ConfigImpl.traceSubstitutionsEnabled()) - ConfigImpl.trace(depth(), "not found in cache, resolving " + original); + ConfigImpl.trace(depth(), + "not found in cache, resolving " + original + "@" + System.identityHashCode(original)); AbstractConfigValue resolved = source.resolveCheckingReplacement(this, original); diff --git a/config/src/main/java/com/typesafe/config/impl/ResolveSource.java b/config/src/main/java/com/typesafe/config/impl/ResolveSource.java index 9e150bad..65fefccd 100644 --- a/config/src/main/java/com/typesafe/config/impl/ResolveSource.java +++ b/config/src/main/java/com/typesafe/config/impl/ResolveSource.java @@ -85,6 +85,8 @@ final class ResolveSource { } void replace(AbstractConfigValue value, ResolveReplacer replacer) { + if (ConfigImpl.traceSubstitutionsEnabled()) + ConfigImpl.trace("Replacing " + value + "@" + System.identityHashCode(value) + " with " + replacer); ResolveReplacer old = replacements.put(value, replacer); if (old != null) throw new ConfigException.BugOrBroken("should not have replaced the same value twice: " @@ -95,6 +97,9 @@ final class ResolveSource { ResolveReplacer replacer = replacements.remove(value); if (replacer == null) throw new ConfigException.BugOrBroken("unreplace() without replace(): " + value); + if (ConfigImpl.traceSubstitutionsEnabled()) + ConfigImpl.trace("Unreplacing " + value + "@" + System.identityHashCode(value) + " which was replaced by " + + replacer); } private AbstractConfigValue replacement(ResolveContext context, AbstractConfigValue value) @@ -131,8 +136,8 @@ final class ResolveSource { AbstractConfigValue resolved; if (ConfigImpl.traceSubstitutionsEnabled()) - ConfigImpl.trace(context.depth(), "resolving " + original + " with trace '" + context.traceString() - + "'"); + ConfigImpl.trace(context.depth(), + "resolving unreplaced " + original + " with trace '" + context.traceString() + "'"); resolved = original.resolveSubstitutions(context); return resolved;