Skip to content

Commit ecafb83

Browse files
author
Dmytro Kostiuchenko
committed
Fixed throwing an IllegalStateException on duplicate HeaderMap
1 parent e3ca341 commit ecafb83

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[
267267
data.queryMapIndex(paramIndex);
268268
isHttpAnnotation = true;
269269
} else if (annotationType == HeaderMap.class) {
270-
checkState(data.queryMapIndex() == null, "HeaderMap annotation was present on multiple parameters.");
270+
checkState(data.headerMapIndex() == null, "HeaderMap annotation was present on multiple parameters.");
271271
data.headerMapIndex(paramIndex);
272272
isHttpAnnotation = true;
273273
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ public void slashAreEncodedWhenNeeded() throws Exception {
308308
assertThat(md.template().decodeSlash()).isTrue();
309309
}
310310

311+
@Test
312+
public void onlyOneHeaderMapAnnotationPermitted() throws Exception {
313+
try {
314+
parseAndValidateMetadata(HeaderMapInterface.class, "multipleHeaderMap", Map.class, Map.class);
315+
Fail.failBecauseExceptionWasNotThrown(IllegalStateException.class);
316+
} catch (IllegalStateException ex) {
317+
assertThat(ex).hasMessage("HeaderMap annotation was present on multiple parameters.");
318+
}
319+
}
320+
311321
interface Methods {
312322

313323
@RequestLine("POST /")
@@ -400,6 +410,12 @@ void login(
400410
@Param("user_name") String user, @Param("password") String password);
401411
}
402412

413+
interface HeaderMapInterface {
414+
415+
@RequestLine("POST /")
416+
void multipleHeaderMap(@HeaderMap Map<String, String> headers, @HeaderMap Map<String,String> queries);
417+
}
418+
403419
interface HeaderParams {
404420

405421
@RequestLine("POST /")

0 commit comments

Comments
 (0)