处理程序处理失败;嵌套异常是 java.lang.StackOverflowError

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38796419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 03:46:33  来源:igfitidea点击:

Handler processing failed; nested exception is java.lang.StackOverflowError

javaspringseleniumselenium-chromedriver

提问by eam.maga

I created a service Restful With Spring framework , and I'm trying to include a method a call to Selenium Java, with the driver Google Chrome , but to create the object WebDriver driver = new ChromeDriver ();

我用 Spring 框架创建了一个 Restful 服务,我试图包含一个调用 Selenium Java 的方法,使用驱动程序 Google Chrome ,但要创建对象 WebDriver driver = new ChromeDriver ();

This me generates a exception :

这我会产生一个异常:

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
    org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1302)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
causa raíz

java.lang.StackOverflowError
    java.lang.Exception.<init>(Exception.java:102)
    java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:89)
    java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:72)
    sun.reflect.GeneratedMethodAccessor95.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:497)
    org.json.JSONObject.populateMap(JSONObject.java:1015)
    org.json.JSONObject.<init>(JSONObject.java:279)
    org.json.JSONObject.wrap(JSONObject.java:1527)
    org.json.JSONObject.populateMap(JSONObject.java:1017)
    org.json.JSONObject.<init>(JSONObject.java:279)
    org.json.JSONObject.wrap(JSONObject.java:1527)
    org.json.JSONObject.populateMap(JSONObject.java:1017)
    org.json.JSONObject.<init>(JSONObject.java:279)
    org.json.JSONObject.wrap(JSONObject.java:1527)

Independent in a main class runs smoothly , but I require it from a service Restful

独立在主班上运行顺利,但我需要从服务 Restful 中获得它

回答by Akshay Joshi

I spent few hours struggling with stackoverflow error ... hope this helps someone

我花了几个小时努力解决 stackoverflow 错误......希望这对某人有所帮助

i made a silly mistake

我犯了一个愚蠢的错误

please see below code snippet :-

请参阅下面的代码片段:-

Incorrect code :-

不正确的代码 :-

Map abcWithKey = new HashMap<>();

abcWithKey.put("key_1", abcWithKey);

Correct Code :-

正确代码:-

Map abcWithKey = new HashMap<>();

abcWithKey.put("key_1", abc);

where abc is a map , so instead of adding abc(different map) i was adding same map recursively.

其中 abc 是地图,所以我没有添加 abc(不同的地图),而是递归地添加相同的地图。

回答by Alexandru Marina

Each thread in a Java application has its own stack, a place where method calls and local variables are stored. The error you mention usually happens when this stack is full, basically the current thread makes a lot of calls to certain methods (this is the happy case; another facet would be an infinite loop).

Java 应用程序中的每个线程都有自己的堆栈,一个存储方法调用和局部变量的地方。您提到的错误通常发生在此堆栈已满时,基本上当前线程对某些方法进行了大量调用(这是一种快乐的情况;另一个方面将是无限循环)。

Try to run the java process with a higher stack size and see if the error happens again. This can be set using the -Xss property: -Xss4m

尝试使用更大的堆栈大小运行java进程,看看是否再次发生错误。这可以使用 -Xss 属性设置:-Xss4m