Skip to content

Commit 4dbbdb7

Browse files
Denis StepanovDenis Stepanov
authored andcommitted
JAXRS: Fix NPE when @path is first on a method
1 parent 67ba4f2 commit 4dbbdb7

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎jaxrs/src/main/java/feign/jaxrs/JAXRSContract.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodA
9090
String pathValue = emptyToNull(Path.class.cast(methodAnnotation).value());
9191
checkState(pathValue != null, "Path.value() was empty on method %s", method.getName());
9292
String methodAnnotationValue = Path.class.cast(methodAnnotation).value();
93-
if (!methodAnnotationValue.startsWith("/") && !data.template().toString().endsWith("/")) {
93+
if (!methodAnnotationValue.startsWith("/") && !data.template().url().endsWith("/")) {
9494
methodAnnotationValue = "/" + methodAnnotationValue;
9595
}
9696
// jax-rs allows whitespace around the param name, as well as an optional regex. The contract should

‎jaxrs/src/test/java/feign/jaxrs/JAXRSContractTest.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@ public void classPathWithTrailingSlashParsesCorrectly() throws Exception {
361361
.hasUrl("/base/specific");
362362
}
363363

364+
@Test
365+
public void methodPathWithoutLeadingSlashParsesCorrectly() throws Exception {
366+
assertThat(parseAndValidateMetadata(MethodWithFirstPathThenGetWithoutLeadingSlash.class, "get").template())
367+
.hasUrl("/base/specific");
368+
}
369+
364370
interface Methods {
365371

366372
@POST
@@ -568,6 +574,13 @@ interface ClassPathWithTrailingSlash {
568574
Response get();
569575
}
570576

577+
@Path("/base/")
578+
interface MethodWithFirstPathThenGetWithoutLeadingSlash {
579+
@Path("specific")
580+
@GET
581+
Response get();
582+
}
583+
571584
private MethodMetadata parseAndValidateMetadata(Class<?> targetType, String method,
572585
Class<?>... parameterTypes)
573586
throws NoSuchMethodException {

0 commit comments

Comments
 (0)