gpt4 book ai didi

java - HTTP 状态 500 - 处理程序处理失败;嵌套异常是 java.lang.StackOverflowError

转载 作者:行者123 更新时间:2023-11-30 06:48:32 26 4
gpt4 key购买 nike

运行我的门户网站一段时间后,出现以下异常。我需要重新登录以消除此错误。因此,我无法在 eclipse 上顺利运行我的开发环境。

这是我的 AuthenticationFilter.java

public class AuthenticationFilter implements Filter {
private static final Logger log = Logger.getLogger(AuthenticationFilter.class) ;
static Map<String, String> permissionsMapping = new HashMap<String, String>();
private static int domainOrGroupParentId = 0;
static {
}

@Override
public void destroy() {
}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

HttpServletRequest servletRequest = (HttpServletRequest) request;

if (servletRequest.getRequestURI().contains("onLoadOfLoginPage")
|| servletRequest.getRequestURI().contains("Corporate")
|| servletRequest.getRequestURI().contains("mainDashboard")
// ||
// servletRequest.getRequestURI().contains("mainDashboardWithoutDomainOrGroupParent")
|| servletRequest.getRequestURI().contains("loginButtonPressedForSuperAdminView")
// ||
// servletRequest.getRequestURI().contains("loginButtonPressedForNonSuperAdmin")
|| servletRequest.getRequestURI().contains("resources")
|| servletRequest.getRequestURI().contains("session")
|| servletRequest.getRequestURI().contains("forgot_password")
|| servletRequest.getRequestURI().contains("resetPassword")) {
>>Line52>> chain.doFilter(request, response);

} else {
HttpSession session = servletRequest.getSession(false);
try {
if (null == session || SessionDataManager.getInstance().getLoggedInWebAdminUser().getWebAdminUserPojo()
.getUsername() == null) {
RequestDispatcher dispatcher = request.getRequestDispatcher("onLoadOfLoginPage");
dispatcher.forward(request, response);
return;

} else if (!servletRequest.getRequestURI().contains("get")) {

String username = (String) SessionDataManager.getInstance().getLoggedInWebAdminUser()
.getWebAdminUserPojo().getUsername();
String sessionID = session.getId();
domainOrGroupParentId = SessionDataManager.getInstance().getDomainIdFromRequest(servletRequest);
log.info("Attempting to maintain Session, with domainParent "+domainOrGroupParentId);
if (!WebAdminHelper.maintainSession(username, sessionID, domainOrGroupParentId)) {
RequestDispatcher dispatcher = request.getRequestDispatcher("onLoadOfLoginPage");
dispatcher.forward(request, response);
return;
}
}
} catch (Exception e) {

}
chain.doFilter(request, response);
}
}

@Override
public void init(FilterConfig arg0) throws ServletException {

}

}

我得到异常

type Exception report

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

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1276)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:958)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
net.codejava.spring.AuthenticationFilter.doFilter(AuthenticationFilter.java:52)
root cause

java.lang.StackOverflowError
com.google.gson.stream.JsonWriter.beforeName(JsonWriter.java:586)
com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:401)
com.google.gson.stream.JsonWriter.value(JsonWriter.java:417)
com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:362)
com.google.gson.internal.bind.TypeAdapters$13.write(TypeAdapters.java:346)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)

编辑我已经确定了根本原因。

response = new Gson().toJson(invException);

类型

InvalidObjectStateException invException

public class InvalidObjectStateException extends Exception {
private static final long serialVersionUID = -9086960433236073019L;
private static final Logger log = Logger.getLogger(InvalidObjectStateException.class);
private String customErrorMessage = null;
private Object exceptionCausingObject = null;

public InvalidObjectStateException(String errorMessage, Object exceptionCausingObject) {
super(errorMessage);
this.customErrorMessage = errorMessage;
log.info("InvalidObjectStateException : exceptionCausingObject"
+ ((exceptionCausingObject != null) ? exceptionCausingObject.getClass().toString() : ""));
this.exceptionCausingObject = exceptionCausingObject;
}

public String getCustomErrorMessage() {
return customErrorMessage;
}

public void setCustomErrorMessage(String customErrorMessage) {
this.customErrorMessage = customErrorMessage;
}

public Object getExceptionCausingObject() {
return exceptionCausingObject;
}

public void setExceptionCausingObject(Object exceptionCausingObject) {
this.exceptionCausingObject = exceptionCausingObject;
}
}

我在这里做错了什么?为什么 Gson 不能解析异常?

最佳答案

Object exceptionCausingObject中的问题

它有循环引用,因此 Gson 解析器无法正确解析它并抛出 StackOverflowError

可以将exceptionCausingObject类的一些字段标记为transient

private transient String name;

这会将它们排除在 Gson 序列化之外。

另一种选择是使用 GraphAdapterBuilder。参见 here

关于java - HTTP 状态 500 - 处理程序处理失败;嵌套异常是 java.lang.StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44167670/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com