perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.64k stars 1.56k forks source link

ConcurrentModificationException - Java 9 #975

Closed GRiMe2D closed 6 years ago

GRiMe2D commented 6 years ago

Sometimes I get ConcurrentModificationException.

I use this code for represent errors to body. Sometimes I get expected (handled) response with 500 status code, sometimes with message of exception

    private void handleExceptions() {
        notFound((request, response) -> this.error(new NotFound(), request, response, 404));
        exception(HttpException.class, (exception, request, response) -> this.error(exception, request, response, exception.statusCode));
        exception(Exception.class, (exception, request, response) -> this.error(exception, request, response, 500));
    }

    private Object error(Exception exception, Request request, Response response, int httpStatusCode) {
        String message = String.valueOf(httpStatusCode) + " - " + exception.getMessage() + "\n" + stackTrace(exception);
        response.type("text/plain");
        response.status(httpStatusCode);
        response.body(message);
        return message;
    }

https://github.com/perwendel/spark/blob/bfda598433a03c3ffc8ea010040270ba011178f3/src/main/java/spark/route/Routes.java#L201

GRiMe2D commented 6 years ago
screen shot 2018-02-10 at 11 15 25 pm
GRiMe2D commented 6 years ago

I'm getting a lot of copies same paths in routes array. ~450. But I have only few routes (~50).

screen shot 2018-02-10 at 11 32 05 pm
GRiMe2D commented 6 years ago

Problem Fixed. I was creating a new controllers in before block, that's why there was a lot of routes.

Maybe disable adding routes after bootstrapping the server?