3

I use IntelliJ IDEA 15.0.4 to develop a Java Play! 2.4.4 application. Since a few months (I think it was because of an IntelliJ update, but not 100% sure) the following problem occurs:

Whenever I call a reverse route from a controller that takes a String as a parameter, the parameter is displayed as an error with the following message:

methodName (string) in ReverseMyController cannot be applied to (java.lang.String)

Here's a code example:

public Result myAction(String myId) {
    // Do something...

    // Redirect back to referrer
    flash("success", "Action was a success");
    if(!myId.isEmpty()) return redirect(controllers.routes.MyController.showItem(myId));
    return redirect(controllers.routes.MyController.itemList(1));
}

In this example, the parameter myId passed to the method showItem would be error highlighted, like this.

I already tried fiddling with the Project Structure settings and searched Google, but to no avail. I hope somebody is able to help me with this, my OCD-self would really appreciate having a code base with no error hints again ;)

Raphael Mäder
  • 776
  • 5
  • 16

2 Answers2

4

Accepted answer does not solve the problem that is why I am answering this old question.

I had the same problem with Play 2.5.4 and InteliJ 2016.1.3

I removed the type (String) from route declaration in routes file and InteliJ stopped highlighting it as error.

Change following:

GET /path/:string_arg controllers.MyController.myMethod(string_arg: String)

To

GET /path/:string_arg controllers.MyController.myMethod(string_arg)

and it works fine.

Arif
  • 1,601
  • 2
  • 21
  • 34
  • It answered the question for Play 2.4.x, but you're indeed correct that your answer solves it for Play 2.5.x. Thanks! – Raphael Mäder Sep 19 '16 at 12:06
  • Any suggestions for play 2.6? Tried this but did not have an impact. I'm using InteliJ 2017.1 with Play 2.6. – Renan Jul 08 '17 at 17:08
3

Yes, I meet the same issue as what you said. I think it is a bug of the IDEA 15.0.4, Have you tried to change to the older version before 15.0.4?

deezh
  • 114
  • 6
  • Thanks, I'll file a bug report in that case. I wasn't sure if it's a bug or a config problem because no one else seemed to have the same problem thus far. – Raphael Mäder Mar 14 '16 at 13:40
  • There was already an issue: https://youtrack.jetbrains.com/issue/SCL-9688 Hope it gets resolved soon :) – Raphael Mäder Mar 14 '16 at 13:46
  • I download IDEA 2016.1 and update scala plugin to 3.0.0, the error message disappeared. – deezh Mar 22 '16 at 06:07
  • 1
    Same for me :) but I had to replace all occurrences of `controllers.routes.MyController` with `routes.MyController` for whatever reason. – Raphael Mäder Mar 24 '16 at 09:07
  • @RaphaelMäder Yes, I also use routes.MyController.:) – deezh Mar 24 '16 at 09:09
  • I downloaded IDEA 2016.1 and updated scala plugin to 3 but the error message didin't change. Then updated to IDEA 2016.2 but the message remains the same:( – erdemlal Jul 19 '16 at 11:39
  • Is there any more suggestion @deezh ? – erdemlal Jul 19 '16 at 15:18
  • You have marked the target/scala-xx/routes/main directory as the Sources Root? if not, please try @erdemlal – deezh Jul 19 '16 at 17:03
  • 2
    @deezh yep, i added but didn't work, i changed `controllers.routes.MyController` with `routes.MyController` like raphael suggested and worked for me too:) – erdemlal Aug 02 '16 at 13:14