Skip to content

OpenFeign interface endpoint - PathVariable annotation was empty on param 0. #863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eno-lc opened this issue May 14, 2023 · 7 comments
Closed

Comments

@eno-lc
Copy link

eno-lc commented May 14, 2023

Describe the bug
Please provide details of the problem, including the version of Spring Cloud that you
are using.
It is my first time facing this and it is kind of confusing. Every time where I have used @PathVariable, I just matched the /{parameter} with the actual parameter on the method so I wouldn't have to do it like this @PathVariable("parameter") Integer parameter, but instead I would do it like @PathVariable Integer parameter for /{parameter}, but when doing the same thing while using OpenFeign there was an error saying " PathVariable annotation was empty on param 0." which is not really true because I have annotated my parameter as a @PathVariable.

This fails and throws 'PathVariable annotation was empty on param 0.'

@FeignClient(name = "fraud-service")
public interface FraudClient {

    @GetMapping("api/v1/fraud-check/{customerId}")
    FraudCheckResponse isFraudster(@PathVariable Integer customerId);

}

This works, correct me if I am wrong but when specifying the method parameter with the same name as the endpoint parameter, there is no need to specify the @PathVariable("thisHere") but I can just use @PathVariable Integer customerId without using the parenthesis on the @PathVariable to specify a value.

@FeignClient(name = "fraud-service")
public interface FraudClient {

    @GetMapping("api/v1/fraud-check/{customerId}")
    FraudCheckResponse isFraudster(@PathVariable("customerId") Integer customerId);

}

Not sure if it is a bug or just a confusion from my side but I just wanted to let you guys know and clarify it for my self as well. Have a great one guys :)

@eno-lc eno-lc changed the title OpenFeign interface endpoin - PathVariable annotation was empty on param 0. OpenFeign interface endpoint - PathVariable annotation was empty on param 0. May 14, 2023
@OlgaMaciaszek OlgaMaciaszek added question Further information is requested waiting for feedback and removed waiting-for-triage question Further information is requested labels Jun 26, 2023
@OlgaMaciaszek
Copy link
Collaborator

Hello @eno-lc. It should, indeed, work and, as far as I can say, it does. Please see a sample branch that works without any issues. If you're still experiencing any issues with it, please provide a minimal, complete, verifiable example that reproduces the issue.

@avdi-vrellaku
Copy link

avdi-vrellaku commented Jul 18, 2023

Hi @OlgaMaciaszek, reaching out from a colleague device here. Having the same issue on a different machine as well, not sure why. I'll provide the link to a repository where you can check the following application/microservice as we get the following error:

Caused by: java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
	at feign.Util.checkState(Util.java:129) ~[feign-core-10.12.jar:na]
	at org.springframework.cloud.openfeign.annotation.PathVariableParameterProcessor.processArgument(PathVariableParameterProcessor.java:51) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
	at org.springframework.cloud.openfeign.support.SpringMvcContract.processAnnotationsOnParameter(SpringMvcContract.java:299) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
	at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:111) ~[feign-core-10.12.jar:na]
	at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:194) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
	at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:62) ~[feign-core-10.12.jar:na]
	at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:151) ~[feign-core-10.12.jar:na]
	at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:49) ~[feign-core-10.12.jar:na]
	at feign.Feign$Builder.target(Feign.java:269) ~[feign-core-10.12.jar:na]
	at org.springframework.cloud.openfeign.DefaultTargeter.target(DefaultTargeter.java:30) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:419) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
	at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:371) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:235) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1249) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.13.jar:5.3.13]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.13.jar:5.3.13]
	... 42 common frames omitted

See the following repository: https://github.com/avdi-vrellaku/microservices-issue-on-empty-param-PathVariable

Clients package contains the FeignClient that I've provided in the bug description
Customer package is where the FeignClient is called
Fraud package contains the controller that is called via the feign client.

@OlgaMaciaszek
Copy link
Collaborator

Hello @avdi-vrellaku, will take a look. Please learn how to properly format code and logs.

@OlgaMaciaszek
Copy link
Collaborator

Hello @avdi-vrellaku @eno-lc - please provide a minimal sample, with only the modules and classes necessary to reproduce your issue.

@spring-cloud-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-cloud-issues
Copy link

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@kaszuster
Copy link

I know this is old and closed. Just wanted to leave this here, to help anyone searching for this error.

OpenFeign/feign#2337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants