1

I'am using play framework 2.6.7 in combination with akka. For field validation i use hibernate validator. I do have issues using hibernate validator

When I call validator.validate(..) i do get a setContextClassloader SecurityException (see below). I "bypassed" the issue by wrapping the call inside a executionContext like this:

  ExecutionContext executionContext = actorSystem.dispatchers().lookup(AKKA_DEFAULT_DISPATCHER);
        executionContext.execute(() -> {
            Set<ConstraintViolation<MyObject>> violations = validator.validate(object);
           ..
        });

For form validations I use/call form.bindFromRequest() method and do still get the same security exception errors.

I tried to use hibernate-validator 5.4.x as well as 6.0.x.

What am I doing wrong ? What is the root cause for that security exceptions ? How can I get rid of it ?

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[SecurityException: setContextClassLoader]]
        at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:255)
        at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:180)
        at dd.cms.ErrorHandler.dd$cms$ErrorHandler$$super$onServerError(ErrorHandler.scala:181)
        at dd.cms.ErrorHandler$$anonfun$onServerError$1.apply(ErrorHandler.scala:188)
        at dd.cms.ErrorHandler$$anonfun$onServerError$1.apply(ErrorHandler.scala:143)
Caused by: java.lang.SecurityException: setContextClassLoader
        at java.util.concurrent.ForkJoinWorkerThread$InnocuousForkJoinWorkerThread.setContextClassLoader(ForkJoinWorkerThread.java:244)
        at play.api.inject.ContextClassLoaderInjector.withContext(Injector.scala:125)
        at play.api.inject.ContextClassLoaderInjector.instanceOf(Injector.scala:118)
        at play.inject.DelegateInjector.instanceOf(DelegateInjector.java:22)
        at play.data.validation.DefaultConstraintValidatorFactory.getInstance(DefaultConstraintValidatorFactory.java:26)
  • Probably related to this issue: https://github.com/playframework/playframework/issues/7751. Could you please create a minimal reproducer? We use Hibernate Validator internally to validate forms, so this is a more weird scenario. – marcospereira Nov 17 '17 at 18:43
  • I disabled default validation module, enabled a custom one in order to implement custom ConstraintValidatorFactory which uses guice instaead of play Injector.Then it works. – transporter39 Dec 15 '17 at 05:39

0 Answers0