From 3c6488fbc2f4875d9c7088bd3dcb2af964f1b064 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 22 Jul 2014 19:43:33 -0400 Subject: [PATCH] Fix 'allow unresolved' for at least two list cases lists did not respond well to cases where only some of their elements were resolved or even when none of them were resolved but one of their object identities happened to change. Previously this would throw a nasty 'bug or broken' exception so it seems unlikely to have unintended side effects. --- .../java/com/typesafe/config/impl/SimpleConfigList.java | 8 ++++++-- .../test/scala/com/typesafe/config/impl/ConfigTest.scala | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleConfigList.java b/config/src/main/java/com/typesafe/config/impl/SimpleConfigList.java index 5ec13f29..ec5a4b98 100644 --- a/config/src/main/java/com/typesafe/config/impl/SimpleConfigList.java +++ b/config/src/main/java/com/typesafe/config/impl/SimpleConfigList.java @@ -98,7 +98,11 @@ final class SimpleConfigList extends AbstractConfigValue implements ConfigList, } if (changed != null) { - return new SimpleConfigList(origin(), changed, newResolveStatus); + if (newResolveStatus != null) { + return new SimpleConfigList(origin(), changed, newResolveStatus); + } else { + return new SimpleConfigList(origin(), changed); + } } else { return this; } @@ -122,7 +126,7 @@ final class SimpleConfigList extends AbstractConfigValue implements ConfigList, return context.resolve(v); } - }, ResolveStatus.RESOLVED); + }, null /* don't force resolve status -- could be allowing unresolved */); } catch (NotPossibleToResolve e) { throw e; } catch (RuntimeException e) { diff --git a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala index a68f3897..568c19a0 100644 --- a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala @@ -1120,9 +1120,10 @@ class ConfigTest extends TestUtils { @Test def allowUnresolvedDoesAllowUnresolved() { - val values = ConfigFactory.parseString("{ foo = 1, bar = 2, m = 3, n = 4}") + val values = ConfigFactory.parseString("{ foo = 1, bar = 2, m = 3, n = 4, unknown = [someVal]}") assertTrue("config with no substitutions starts as resolved", values.isResolved) - val unresolved = ConfigFactory.parseString("a = ${foo}, b = ${bar}, c { x = ${m}, y = ${n}, z = foo${m}bar }, alwaysResolveable=${alwaysValue}, alwaysValue=42") + val unresolved = ConfigFactory.parseString( + "l = [${unknown}[]], l2 = [${unknown}, ${alwaysValue}], a = ${foo}, b = ${bar}, c { x = ${m}, y = ${n}, z = foo${m}bar }, alwaysResolveable=${alwaysValue}, alwaysValue=42") assertFalse("config with substitutions starts as not resolved", unresolved.isResolved) // resolve() by default throws with unresolveable substs