Skip to content

Commit

Permalink
Skip static methods on config interfaces
Browse files Browse the repository at this point in the history
Skip over static methods declared on config interfaces when constructing
the proxy in ConfigProxyFactory.
  • Loading branch information
kilink committed Aug 16, 2024
1 parent ffed4cb commit f12296c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.Collections;
Expand Down Expand Up @@ -232,6 +233,9 @@ <T> T newProxy(final Class<T> type, final String initialPrefix, boolean immutabl
// Each setter will be mapped to a Property<T> for the property name:
// prefix + lowerCamelCaseDerivedPropertyName
for (Method method : type.getMethods()) {
if (Modifier.isStatic(method.getModifiers())) {
continue;
}
MethodInvokerHolder methodInvokerHolder = buildInvokerForMethod(type, prefix, method, proxyObject, immutable);

propertyNames.put(method, methodInvokerHolder.propertyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,28 @@ public void testNestedInterfaceWithCustomDecoder() {
assertEquals(5, proxy.intValue());
assertEquals("BLAH", proxy.customValue().value());
}

@Configuration(prefix = "config")
public interface ConfigWithStaticMethods {
@PropertyName(name = "foo")
@DefaultValue("foo-value")
String foo();

static String bar() {
return "bar-value";
}

static int baz(int x) {
return x + 1;
}
}

@Test
public void testInterfaceWithStaticMethods() {
SettableConfig config = new DefaultSettableConfig();
config.setProperty("config.foo", "foo-value-updated");
ConfigProxyFactory proxyFactory = new ConfigProxyFactory(config, config.getDecoder(), DefaultPropertyFactory.from(config));
ConfigWithStaticMethods configWithStaticMethods = proxyFactory.newProxy(ConfigWithStaticMethods.class);
assertEquals("foo-value-updated", configWithStaticMethods.foo());
}
}

0 comments on commit f12296c

Please sign in to comment.