title: Using FormFactory in Play 2.5.18 causes InvocationTargetException error
body: <p>I am upgrading the Form objects in Play 2.5.18 to use the FormFactory object as listed here:</p>
  
  <p><a href="https://www.playframework.com/documentation/2.5.18/JavaForms" rel="nofollow noreferrer">https://www.playframework.com/documentation/2.5.18/JavaForms</a></p>
  
  <p>I have my controller looking like this:</p>
  
  <pre><code>public class Application extends Controller {
  
      public final MailerClient mailerClient;
      public final FormFactory formFactory;
      public final MessagesApi messagesApi;
      public final Collection&lt;Lang&gt; candidates;
      public final Messages messages;
  
      @Inject
      public Application(MailerClient mailerClient, FormFactory formFactory, MessagesApi messagesApi) {
          this.mailerClient = mailerClient;
          this.formFactory = formFactory;
          this.messagesApi = messagesApi;
          this.candidates = Collections.singletonList(new Lang(Locale.US));
          this.messages = messagesApi.preferred(candidates);
      }
  
      public Result authenticate() {
          String errorMessage = "";
  
          Form&lt;Login&gt; loginForm = formFactory.form(Login.class).bindFromRequest();
          Logger.debug("authenticate");
  
          ...
      }
      ...
  }
  </code></pre>
  
  <p>When I run the application and attempt to login, I receive this error:</p>
  
  <pre><code>! @77hah0j80 - Internal server error, for (POST) [/auth] -&gt;
  
  play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[RuntimeException: java.lang.reflect.InvocationTargetException]]
          at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:255)
          at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:182)
          at play.core.server.AkkaHttpServer$$anonfun$$nestedInanonfun$executeHandler$1$1.applyOrElse(AkkaHttpServer.scala:230)
          at play.core.server.AkkaHttpServer$$anonfun$$nestedInanonfun$executeHandler$1$1.applyOrElse(AkkaHttpServer.scala:229)
          at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:414)
          at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
          at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
          at play.api.libs.streams.Execution$trampoline$.executeScheduled(Execution.scala:109)
          at play.api.libs.streams.Execution$trampoline$.execute(Execution.scala:71)
          at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:68)
  Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
          at play.data.Form.callLegacyValidateMethod(Form.java:495)
          at play.data.Form.bind(Form.java:530)
          at play.data.Form.bindFromRequest(Form.java:257)
          at controllers.Application.authenticate(Application.java:342)
          at router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$64(Routes.scala:2254)
          at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:136)
          at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:135)
          at play.core.routing.HandlerInvokerFactory$JavaActionInvokerFactory$$anon$8$$anon$2$$anon$1.invocation(HandlerInvoker.scala:110)
          at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:78)
          at play.http.DefaultActionCreator$1.call(DefaultActionCreator.java:31)
  Caused by: java.lang.reflect.InvocationTargetException: null
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at play.data.Form.callLegacyValidateMethod(Form.java:486)
          at play.data.Form.bind(Form.java:530)
          at play.data.Form.bindFromRequest(Form.java:257)
          at controllers.Application.authenticate(Application.java:342)
          at router.Routes$$anonfun$routes$1.$anonfun$applyOrElse$64(Routes.scala:2254)
          at play.core.routing.HandlerInvokerFactory$$anon$3.resultCall(HandlerInvoker.scala:136)
  Caused by: java.lang.NullPointerException: null
          at play.i18n.MessagesApi.preferred(MessagesApi.java:131)
          at controllers.Application$Login.validate(Application.java:133)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at play.data.Form.callLegacyValidateMethod(Form.java:486)
          at play.data.Form.bind(Form.java:530)
          at play.data.Form.bindFromRequest(Form.java:257)
          at controllers.Application.authenticate(Application.java:342)
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>at controllers.Application.authenticate(Application.java:342)
  </code></pre>
  
  <p>is this line of code:</p>
  
  <pre><code>Form&lt;Login&gt; loginForm = formFactory.form(Login.class).bindFromRequest();
  </code></pre>
  
  <p>I have found a few posts, but they seem to point to what I am doing already:</p>
  
  <p><a href="https://stackoverflow.com/questions/36099834/the-method-formclasst-from-form-class-is-deprecated-in-play-framework">The method form(Class&lt;T&gt;) from Form class is deprecated in Play! Framework</a></p>
  
  <p><a href="https://stackoverflow.com/questions/40339240/formfactory-form-doesnt-exist-playframework">formFactory.form() doesn&#39;t exist ! PlayFramework</a></p>
  
  <p>I think this is an easy fix and appreciate the help.</p>
  
  <p>---------------------------- EDIT ------------------------------</p>
  
  <p>Image of variables in Eclipse:
  <a href="https://i.stack.imgur.com/qCzEv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qCzEv.png" alt="enter image description here"></a></p>