matteobaccan/owner

Expanded property keys are not reported by Accessible methods

Opened this issue · 1 comments

If I try to use the expansion method
E.g. if I define

public interface MyProjectConfig extends Config, Accessible {
	@Key("myproject.prefix")
	@DefaultValue("myproject")
	String configPrefix();

	@Key("${myproject.prefix}" + ".debug")
	@DefaultValue("false")
	boolean debug();
}

And elsewhere I try to load the config and use the Accessible methods

    config = ConfigCache.getOrCreate(MyProjectConfig.class);
    // Log all the properties using Accessible.store
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    config.store(new PrintStream(out), "--- loaded properties ---");
    out.flush();
    log.info(out);

    // Again, using Accessible.list
    out = new ByteArrayOutputStream();
    config.list(new PrintStream(out));
    out.flush();			
    log.info(out);

    // Now get property names
    log.info("Property names:"  + config.propertyNames());

They I get duplicate properties, ones with the values loaded from the external files and other with the default values, but without any expansion applied to the keys:

myproject.debug=true
${myproject.prefix}.debug=true

etc.
Nonetheless, when using the config interface methods, it returns the appropriate values:

    log.info("Debug mode: " + config.debug());

2018-05-15 18:11:18,251 INFO [...] Debug mode: true

Hi.

The expansion is resolved at run time, when you call the method. This is why you don't see it in properties lists.

I think it's not a wrong behavior: it dumps its internal structure, and to me it looks consistent as behavior.

Luigi.