Netflix / archaius

Library for configuration management API
Apache License 2.0
2.47k stars 486 forks source link

@Configuration(prefix = "foo") on an interface, in conjunction with a parameterized @PropertyName fails #676

Closed akang31 closed 1 year ago

akang31 commented 1 year ago

When applying @Configuration(prefix = "foo") on an interface, we would expect that any @PropertyNames specified in the interface would automatically look for foo.[names], but this does not apply when there are parameters specified, instead using the PropertyName directly.

Example

@Configuration(prefix = "foo") 
interface BogusConfiguration {
  @DefaultValue("BAD")
  @PropertyName(name = "bar")
  String getFooBar();

  @DefaultValue("BAD")
  @PropertyName(name = "${0}")
  String getFoo(String bar);
}

Given config

foo.bar: "GOOD"
foo.baz: "ALSO GOOD"
bar: "ALSO BAD"

Expected

getFooBar() --> GOOD
getFoo("bar") --> GOOD
getFoo("baz") --> ALSO GOOD

Actual

getFooBar() --> GOOD
getFoo("bar") --> ALSO BAD
getFoo("baz") --> BAD // From the default value

Issue is in ConfigProxyFactory.createParameterizedProperty.

Changing this to only the correct behavior would be breaking for many clients, we will include backward compatibility for cases in which clients specify the prefix (e.g. in the above example, a name = "foo.${0}" would also produce the same result).

This would however still be breaking for clients that specified a prefix at the top level config, and then ignored it in the body.