cfg4j / cfg4j

Modern configuration library for distributed apps written in Java.

Home Page:http://cfg4j.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Misinterpreting Java 8 default methods

timotei opened this issue · comments

It seems that having default methods will trigger an exception that cfg4j doesn't find that configuration. However, in my opinion we should ignore those kind of methods, here's an example that throws:

public interface Configuration {
    string apiKey();

    default String stringRepresentation() {
        return String.format(
            "apiKey=%s", apiKey);
    }
}

And the relevant exception:

Exception in thread "main" java.util.NoSuchElementException: No configuration with key: stringRepresentation
	at org.cfg4j.provider.SimpleConfigurationProvider.getProperty(SimpleConfigurationProvider.java:94)
	at org.cfg4j.provider.SimpleConfigurationProvider.getProperty(SimpleConfigurationProvider.java:76)
	at org.cfg4j.provider.BindInvocationHandler.invoke(BindInvocationHandler.java:61)
	at com.sun.proxy.$Proxy0.stringRepresentation(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.cfg4j.validator.BindingValidator.validate(BindingValidator.java:51)
	at org.cfg4j.provider.SimpleConfigurationProvider.bind(SimpleConfigurationProvider.java:128)
	at org.cfg4j.provider.SimpleConfigurationProvider.bind(SimpleConfigurationProvider.java:106)

What do you think?