IntelliJ and SonarQube , Local Variable is redundant

IntelliJ is saying Local Variable is redundant. I placed the equation there to store it, so I can debug/see the variable before returning it. Is there any easy way to debug, or else, I would have to copy the whole variable equation in the debugger window to see its value.

enter image description here

Answer

IntelliJ IDEA offers several ways to evaluate expressions while in debug mode:

  1. The obvious one, by hovering over a variable or by having a look at the automatically added local variable watches. This is what you are doing now, but forces you to change the code in such a way that you have such a variable and some static code analysis tools will complain.

  2. Add a manual watch for the variable or expression you are interested in.

  3. Select an expression or subexpression, right click and select Quick Evaluate Expression

  4. Hover over a (sub-)expression, hold Alt and left click

Note that point 2–4 will re-evaluate any expression. If you have side effects or non-idempotent expressions, you might not want to do this. In that case, your only choice is a temporary and redundant variable.