question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException in ProxyExchangeArgumentResolver

See original GitHub issue

Describe the bug

I have a proxy gateway setup very similar to the one in the documentation. https://cloud.spring.io/spring-cloud-gateway/reference/html/#building-a-simple-gateway-by-using-spring-mvc-or-webflux

In version 2.2.1 everything works fine. In version 2.2.2 there following error occurs:

Caused by: java.lang.NullPointerException: null
	at org.springframework.cloud.gateway.mvc.config.ProxyExchangeArgumentResolver.resolveArgument(ProxyExchangeArgumentResolver.java:81)

Every version since 2.2.2 results in the same error. I believe this will happen whenever org.springframework.cloud.gateway.mvc.config.ProxyExchangeArgumentResolver::autoForwardedHeaders is null. https://github.com/spring-cloud/spring-cloud-gateway/blob/d2ea0ebd822b71c70a6e1bb4bfc7bf73423ac051/spring-cloud-gateway-mvc/src/main/java/org/springframework/cloud/gateway/mvc/config/ProxyExchangeArgumentResolver.java#L48

Sample

I don’t have a sample, but it should be pretty easy to prove with a unit test and the code problem seems obvious (although I have very little experience looking at spring source code).

Code indicating autoForwardedHeaders can be null:

    public void setAutoForwardedHeaders(Set<String> autoForwardedHeaders) {
        this.autoForwardedHeaders = autoForwardedHeaders == null ? null
                : autoForwardedHeaders.stream().map(String::toLowerCase).collect(toSet());
    }

https://github.com/spring-cloud/spring-cloud-gateway/blob/d2ea0ebd822b71c70a6e1bb4bfc7bf73423ac051/spring-cloud-gateway-mvc/src/main/java/org/springframework/cloud/gateway/mvc/config/ProxyExchangeArgumentResolver.java#L60

Code where there’s no null check:

        if (this.autoForwardedHeaders.size() > 0) {
            proxy.headers(extractAutoForwardedHeaders(webRequest));
        }

https://github.com/spring-cloud/spring-cloud-gateway/blob/d2ea0ebd822b71c70a6e1bb4bfc7bf73423ac051/spring-cloud-gateway-mvc/src/main/java/org/springframework/cloud/gateway/mvc/config/ProxyExchangeArgumentResolver.java#L79

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
manueldevelopercommented, Feb 28, 2021

Hi @spencergibb I’ve created the following PR #2163 which solves the issue. I hope that all is ok, if not, let me know and I’d try to solve asap. Thanks!

1reaction
spencergibbcommented, Feb 17, 2021

Great. Let me know if you need some help

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException in ProxyExchangeArgumentResolver
I have a proxy gateway setup very similar to the one in the documentation. https://cloud.spring.io/spring-cloud-gateway/reference/html/#building-a-simple- ...
Read more >
SpringMvc java.lang.NullPointerException When Posting ...
This works fine, however when the form is posted to the server i call the same exact function i would call in the...
Read more >
Can I alter the RestTemplate used in Spring's ProxyExchange?
We altered RestTemplate using ProxyExchangeArgumentResolver class. below is code ... authentication in Spring: List of providers throws NullPointerException ...
Read more >
spring boot 项目集成网关问题 - CSDN博客
NullPointerException. at org.springframework.cloud.gateway.mvc.ProxyExchange.<init>(ProxyExchange.java:167) ~[spring-cloud-gateway-mvc-2.1.0 ...
Read more >
caused by: java.lang.nullpointerexception: null at springfox ...
On the analysis of the code snippet given, the null pointer exception occurred since your code doesn't ask the spring dependency injector to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found