Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove 'Assignment of Parameter 'variable' is not allowed'

Tags:

java

sonarqube

I'm programming a Controller using Java and I'm checking the style using Sonar. In my Sonar I have an error that says:

'Assignment of Parameter 'variable' is not allowed.

The line that it's on is:

@RequestParam(value="variable", required=false) String variable

So I'm wondering how I could get that error off since I can't just create a setter when I'm using that annotation.

EDIT

I'm using Eclipse. The rule being broke is Parameter Assignment.

@RequestParam(value="variable", required=false) String variable
if (variable != null && variable.compareTo("") == 0) {
    variable = null;
}
like image 622
apkisbossin Avatar asked Jul 08 '15 17:07

apkisbossin


1 Answers

In your if condition block, you are setting variable to null and it happens to be your method parameter. Instead of assigning the value to the method parameter, create a local variable and use it and return the value of the local variable from the method if at all it is intended.

like image 110
systemhalted Avatar answered Sep 29 '22 17:09

systemhalted