Reputation: 344
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.
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;
}
Upvotes: 8
Views: 16951
Reputation: 818
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.
Upvotes: 5