From 3c6488fbc2f4875d9c7088bd3dcb2af964f1b064 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 22 Jul 2014 19:43:33 -0400 Subject: [PATCH 1/2] 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 From ed19f4c09e8577fae5dbd8ce4446abe183b2d428 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 24 Dec 2014 16:10:20 -0500 Subject: [PATCH 2/2] isolate test for allowing unresolved list elements --- .../com/typesafe/config/impl/ConfigTest.scala | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 568c19a0..b6368299 100644 --- a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala @@ -1118,12 +1118,20 @@ class ConfigTest extends TestUtils { assertTrue("after resolution, config is now resolved", resolved2.isResolved) } + @Test + def allowUnresolvedDoesAllowUnresolvedArrayElements() { + val values = ConfigFactory.parseString("unknown = [someVal], known = 42") + val unresolved = ConfigFactory.parseString("concat = [${unknown}[]], sibling = [${unknown}, ${known}]") + unresolved.resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true)) + unresolved.withFallback(values).resolve() + unresolved.resolveWith(values) + } + @Test def allowUnresolvedDoesAllowUnresolved() { - val values = ConfigFactory.parseString("{ foo = 1, bar = 2, m = 3, n = 4, unknown = [someVal]}") + val values = ConfigFactory.parseString("{ foo = 1, bar = 2, m = 3, n = 4}") assertTrue("config with no substitutions starts as resolved", values.isResolved) - 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") + val unresolved = ConfigFactory.parseString("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