How to disable this inspection: "Variable is already assigned to this value"
In my newly updated Intellij I am now getting a warning in code that looks like this:
public void foo(SomeClass c) {
c = conditionallyProcess(c);
// do some things with c here
}
The warning is "Variable is already assigned to this value", with the explanation that this is potentially confusing code. My issue with it is there is no way to disable this inspection, at least that I can find. Is this a defect? Or am I missing something?
By the way, the rationale for code like this is because C is immutable, and "conditionallyProcess" will create a modified copy if it has to. If not it will return the same instance. I believe that assigning the return value of conditinallyProcess to a new variable is more confusing. It would cause two variables of the same type to be in scope with the potential to use the method parameter instead of the modified copy.
Please sign in to leave a comment.
Hello Robert,
You could disable "Variable is assigned to itself" inspection in "File | Settings | Editor | Inspections | Java - Declaration redundancy".
Thanks. I think there's still a defect here. Shouldn't Alt-Enter bring up a dialog that allows me to disable this inspection, as with other warnings?
Robert,
Yes, it should. Could you please attach screenshot when "Alt+Enter" is pressed?
I have the same trouble and it does not make any sense at all.
Hi Literakl,
Can you please clarify the issue? In case you want to disable the inspection, after pressing Alt+Enter, please press the right arrow and you will be suggested the list of actions that includes the disabling of the inspection as well. Here is the sample: