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.


Comment actions Permalink

Hello Robert,

You could disable "Variable is assigned to itself" inspection in "File | Settings | Editor | Inspections | Java - Declaration redundancy".

Comment actions Permalink

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?

Comment actions Permalink


Yes, it should. Could you please attach screenshot when "Alt+Enter" is pressed?


Please sign in to leave a comment.