Skip to content

Commit

Permalink
Merge pull request #728 from Netflix/ignore-static-methods
Browse files Browse the repository at this point in the history
Skip static methods on config interfaces
  • Loading branch information
rgallardo-netflix authored Aug 19, 2024
2 parents ffed4cb + f12296c commit 3424aa3
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 3424aa3

Please sign in to comment.