feign icon indicating copy to clipboard operation
feign copied to clipboard

Can't determine if RequestTemplate or Request has a null body

Open jebeaudet opened this issue 4 years ago • 2 comments

Hi

In the process of updating feign from version 10.2.3 to 10.7.4, I noticed some deprecation in my codebase on internal code dealing with RequestTemplate and Request. The methods RequestTemplate::requestBody has been marked as deprecated and Request::requestBody has been removed.

I'm fine with moving on and building something better obviously but it seems there is no non deprecated replacement to detect a null body in both classes. For example, this simple code will throw a NPE :

    public static void main(String[] args)
    {
        Request.create(HttpMethod.GET,
                       "http://patate.com",
                       Collections.emptyMap(),
                       (Request.Body) null,
                       (RequestTemplate) null)
               .body();
    }

If there is a non nullability constraint in both classes, there should be preconditions in the constructors and clear java documentation for users.

Thanks

jebeaudet avatar Apr 16 '20 00:04 jebeaudet

@jebeaudet

Documentation in the latest version does indicate that body and requestTemplate can be null, however the function Request#body does not properly check the body to ensure that it is present. This is an oversight on our part. I've marked this issue as a bug for us to triage and correct. Thanks!

kdavisk6 avatar Apr 25 '20 19:04 kdavisk6

Hello,

I am having the same issue as @jebeaudet. I saw the fix PR was closed, and no other PRs were linked.

Will this issue be tackled? Or do you have any recommendation to check whether a RequestTemplate contains a non body?

Thanks,

Dainerx avatar May 17 '23 17:05 Dainerx