Skip to content
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

NoSuchMethodError com.netflix.zuul.context.RequestContext.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView; #410

Open
esteveblanch opened this issue Mar 7, 2018 · 2 comments

Comments

@esteveblanch
Copy link

esteveblanch commented Mar 7, 2018

Hello,

I am using zuul-core 1.3.0 with Spring-Cloud in a JDK 1.7 environment.
I started getting a strange error when executing zuul:

com.netflix.zuul.exception.ZuulException: Filter threw Exception
	at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:227) [zuul-core-1.3.0.jar:1.3.0]
	at com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:157) [zuul-core-1.3.0.jar:1.3.0]
	at com.netflix.zuul.FilterProcessor.preRoute(FilterProcessor.java:133) [zuul-core-1.3.0.jar:1.3.0]
	at com.netflix.zuul.ZuulRunner.preRoute(ZuulRunner.java:105) [zuul-core-1.3.0.jar:1.3.0]
	at com.netflix.zuul.http.ZuulServlet.preRoute(ZuulServlet.java:125) [zuul-core-1.3.0.jar:1.3.0]
	at com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:74) [zuul-core-1.3.0.jar:1.3.0]
	at org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.java:157) [spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
	at org.springframework.cloud.netflix.zuul.web.ZuulController.handleRequest(ZuulController.java:44) [spring-cloud-netflix-core-1.4.3.RELEASE.jar:1.4.3.RELEASE]
	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50) [spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) [spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) [spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) [spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) [tomcat-embed-core-7.0.81.jar:7.0.81]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.12.RELEASE.jar:4.3.12.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) [tomcat-embed-core-7.0.81.jar:7.0.81]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) [tomcat-embed-core-7.0.81.jar:7.0.81]
..........
Caused by: java.lang.NoSuchMethodError: com.netflix.zuul.context.RequestContext.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
	at com.netflix.zuul.context.RequestContext.copy(RequestContext.java:546) ~[zuul-core-1.3.0.jar:1.3.0]
	at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:190) ~[zuul-core-1.3.0.jar:1.3.0]
	... 109 more

Apparently it seems all ok, but, after some hours of investigation, i arrived at this gist: https://gist.github.com/AlainODea/1375759b8720a3f9f094

Basically it says that the method keySet() in ConcurrentHashMap, has different return type in JDK 1.7 and JDK 1.8. In JDK 1.7, it returns a Set and in JDK 1.8 it returns a KeySetView.

It my be possible that if you compile code using JDK 1.8, but with compatibility with JDK 1.7, this kind of errors may rise.

I checked that jar artifacts deployed on maven central, are compiled with JDK 1.8, and if you see the staktrace, the code specs a KeySetView.

I decompiled the source code of the jar, and if we inspect the bytecode of the RequestContext in the method copy():

         L9 {
             aload0 // reference to self
             invokevirtual com/netflix/zuul/context/RequestContext keySet(()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;);
             invokevirtual java/util/concurrent/ConcurrentHashMap$KeySetView iterator(()Ljava/util/Iterator;);
             astore2
         }

Effectively appears a reference to KeySetView, that does not exists in JDK 1.7.

The immediate solution to this problem, is compile the source code using JDK 1.7, and not using JDK 1.8.

I will try this to check if effectively compiling zuul with JDK 1.7 solves this problem.

@esteveblanch
Copy link
Author

I downloaded the source code of zuul-core 1.3.0 and I compiled using the JDK 1.7.

The decompiled bycode source now is different and there is no reference to KeySetView:

         L9 {
             aload0 // reference to self
             invokevirtual com/netflix/zuul/context/RequestContext keySet(()Ljava/util/Set;);
             invokeinterface java/util/Set iterator(()Ljava/util/Iterator;);
             astore2
         }

I added the jar compiled with JDK 1.7 to my application, and the exception does not appears any more, and it works as expected.

@artgon artgon added the spring label Mar 7, 2018
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants