Skip to content

Commit 486bf63

Browse files
Dan JasekAdrian Cole
authored andcommitted
Ignore static methods when validating interface
Also moved tests to compile to Java 1.8 fixes OpenFeign#312
1 parent af5bf09 commit 486bf63

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ notifications:
88
on_failure: always # options: [always|never|change] default: always
99
on_start: false # default: false
1010
jdk:
11-
- oraclejdk7
11+
- oraclejdk8
1212
install: ./installViaTravis.sh
1313
script: ./buildViaTravis.sh
1414
cache:

core/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ dependencies {
1010
testCompile 'com.google.code.gson:gson:2.5' // for example
1111
testCompile 'org.springframework:spring-context:4.2.5.RELEASE' // for example
1212
}
13+
14+
configure(compileTestJava) {
15+
sourceCompatibility = 1.8
16+
targetCompatibility = 1.8
17+
}

core/src/main/java/feign/Contract.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.lang.annotation.Annotation;
1919
import java.lang.reflect.Method;
20+
import java.lang.reflect.Modifier;
2021
import java.net.URI;
2122
import java.util.ArrayList;
2223
import java.util.Collection;
@@ -55,7 +56,8 @@ public List<MethodMetadata> parseAndValidatateMetadata(Class<?> targetType) {
5556
}
5657
Map<String, MethodMetadata> result = new LinkedHashMap<String, MethodMetadata>();
5758
for (Method method : targetType.getMethods()) {
58-
if (method.getDeclaringClass() == Object.class) {
59+
if (method.getDeclaringClass() == Object.class ||
60+
(method.getModifiers() & Modifier.STATIC) != 0) {
5961
continue;
6062
}
6163
MethodMetadata metadata = parseAndValidateMetadata(targetType, method);

core/src/test/java/feign/DefaultContractTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,21 @@ public void missingMethod() throws Exception {
693693

694694
contract.parseAndValidatateMetadata(MissingMethod.class);
695695
}
696+
697+
interface StaticMethodOnInterface {
698+
@RequestLine("GET /api/{key}")
699+
String get(@Param("key") String key);
700+
701+
static String staticMethod() {
702+
return "value";
703+
}
704+
}
705+
706+
@Test
707+
public void staticMethodsOnInterfaceIgnored() throws Exception {
708+
List<MethodMetadata> mds = contract.parseAndValidatateMetadata(StaticMethodOnInterface.class);
709+
assertThat(mds).hasSize(1);
710+
MethodMetadata md = mds.get(0);
711+
assertThat(md.configKey()).isEqualTo("StaticMethodOnInterface#get(String)");
712+
}
696713
}

0 commit comments

Comments
 (0)