Useful or not, from you.
playframework SecurityException in Play dev environment

I am getting an error as follows when in controller calling play.data.FormFactory.form(FormData.class).bindFromRequest() and when a form bean has any play.data.validation.Constraints annotations.

The problem happens only in development environment when running application via sbt run. When I pack an application using sbt stage and run using generated bash, the error does not appear - all works as expected.

Have you seen similar behaviour? Are you aware of any settings for a dev environment which could cause that?

Edit This issue happens only when FormFactory.form(Class).bindFromRequest() is called directly from a controller handler method. If it is called using CompletableFuture.supplyAsync(handler, ec) where ec is either HttpExecutionContext.current or other extension of CustomExecutionContext then the problem does not happen.

java.util.concurrent.CompletionException: java.lang.SecurityException: setContextClassLoader
	at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
	at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
	at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:604)
	at java.util.concurrent.CompletableFuture.uniApplyStage(CompletableFuture.java:614)
	at java.util.concurrent.CompletableFuture.thenApply(CompletableFuture.java:1983)
	at controllers.TriggerController.trigger(TriggerController.java:73)
	at admin_api_v1.Routes$$anonfun$routes$1.$anonfun$applyOrElse$184(Routes.scala:2594)
	at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:137)
	at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$8$$anon$2$$anon$1.invocation(HandlerInvoker.scala:108)
	at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:88)
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)
	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.createAndInitializeValidator(ConstraintValidatorManager.java:145)
	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.getInitializedValidator(ConstraintValidatorManager.java:109)
	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getConstraintValidatorNoUnwrapping(ConstraintTree.java:301)
	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getConstraintValidatorInstanceForAutomaticUnwrapping(ConstraintTree.java:242)
	at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getInitializedConstraintValidator(ConstraintTree.java:163)

Play Version: 2.6.11, SBT: 1.1.0

API: Java

Operating System: MacOS 10.11.6

JDK: Oracle 1.8.0_161

java version "1.8.0_161" Java(TM) SE Runtime Environment (build 1.8.0_161-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

That's a useful answer
Without any help

@patrickliangli Can you give more details? Which version of Play are you using? And also which version of deadbolt? Which deadbolt annotation did you use (I maintain deadbolt so this information would help)?