问题
I know the title isn't the best, but the error is not clear at all to me. The error I have is this:
019-04-15 14:28:45.270 ERROR 12644 --- [nio-9090-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause
java.lang.StackOverflowError: null
at com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:401) ~[gson-2.8.5.jar:na]
at com.google.gson.stream.JsonWriter.value(JsonWriter.java:480) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.TypeAdapters$3.write(TypeAdapters.java:148) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.TypeAdapters$3.write(TypeAdapters.java:133) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:127) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:245) ~[gson-2.8.5.jar:na]
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69) ~[gson-2.8.5.jar:na]
at
[...]
The [...]
is because these lines repeat for a crazy amount of time and they're all the same. For what I understood by searching the error, it should be some problem with recursivity and infinite loop, but in my code I don't get where this is.
This is the method I'm calling:
@PostMapping(path=PathConstants.START_ACTION)
public ResponseEntity<BaseResponse<ProcessInstance>> start(@PathVariable String processDefinitionId, @RequestBody(required=false) Map<String,Object> params) throws FileNotFoundException {
LOGGER.info("starting process definition with id {}", processDefinitionId);
ResponseEntity<BaseResponse<ProcessInstance>> response = null;
ProcessInstance pi = null;
LocalDateTime time = LocalDateTime.now();
try {
if(params!=null) {
pi = runtimeService.startProcessInstanceById(processDefinitionId, params);
List<org.flowable.task.api.Task> tasks = taskService.createTaskQuery().list();
System.out.println("Length " + tasks.get((tasks.size()-1)).getProcessVariables());
org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
if(task==null) {
System.out.println("Task is null");
} else {
System.out.println("Info task " + runtimeService.getVariables(pi.getId()));
}
} else {
System.out.println("Empty ");
pi = runtimeService.startProcessInstanceById(processDefinitionId);
}
response = new ResponseEntity<>(new BaseResponse<>(Constants.OK, pi), HttpStatus.OK);
MongoOperations.writeLogSuccess(pi ,pi.getProcessDefinitionName(), "OK"); //if it went well
} catch (FlowableObjectNotFoundException e) {
String pdn = repositoryService.getProcessDefinition(processDefinitionId).getName();
MongoOperations.writeLogFailure(time, pdn, "KO not found");
response = new ResponseEntity<>(new BaseResponse<>(e.getMessage(), null), HttpStatus.NOT_FOUND);
}
catch (FlowableException e) { //TEST EXCEPTION WITH FAILSTATUSCODE
String pdn = repositoryService.getProcessDefinition(processDefinitionId).getName();
MongoOperations.writeLogFailure(time, pdn, "KO flowable");
response = new ResponseEntity<>(new BaseResponse<>(e.getMessage(), null), HttpStatus.INTERNAL_SERVER_ERROR); //other exception are managed here
} catch(Exception e) {
String pdn = repositoryService.getProcessDefinition(processDefinitionId).getName();
MongoOperations.writeLogFailure(time, pdn, "KO general");
response = new ResponseEntity<>(new BaseResponse<>(e.getMessage(), null), HttpStatus.INTERNAL_SERVER_ERROR); //other exception are managed here
}
return response;
}
I really don't understand what's causing this and why. The params
I'm passing through post request is a Json string written in this way:
{
"input":2
}
来源:https://stackoverflow.com/questions/55689432/java-lang-stackoverflowerror-null-jsonwriter-writedeferredname-but-not-using-js