IntelliJ - warning message does not appear for condition i> = 2, when I know

Next IntelliJ Program

public static void main(String[] args) { int i = 0; if (i <= 2) { System.out.println("ok"); } } 

warns me: “Condition“ i <= 2 ”is always“ true. ”If I replace the condition with i > 2 , I get“ Condition ”i> 2 is always“ false. ”The same goes with i == 2 .

But if I replace it with i >= 2 , I have no warnings.

Why doesn't IntelliJ warn me in the latter case that this condition is always wrong?

I am using IntelliJ 14.1.5, and the compiler used is javac in version 1.8.0_51.

enter image description here

+6
source share
2 answers

As Paul Boddington said in a comment, JetBrains actually forgot to implement something in his algorithm, which was fixed a few days ago .

Before:

 if (opSign == LT && comparedWith <= rangeMin) return alwaysFalse(instruction, runner, memState); if (opSign == LT && comparedWith > rangeMax) return alwaysTrue(instruction, runner, memState); if (opSign == LE && comparedWith >= rangeMax) return alwaysTrue(instruction, runner, memState); if (opSign == GT && comparedWith >= rangeMax) return alwaysFalse(instruction, runner, memState); if (opSign == GT && comparedWith < rangeMin) return alwaysTrue(instruction, runner, memState); if (opSign == GE && comparedWith <= rangeMin) return alwaysTrue(instruction, runner, memState); 

After:

 if (opSign == LT && comparedWith <= rangeMin) return alwaysFalse(instruction, runner, memState); if (opSign == LT && comparedWith > rangeMax) return alwaysTrue(instruction, runner, memState); if (opSign == LE && comparedWith >= rangeMax) return alwaysTrue(instruction, runner, memState); if (opSign == LE && comparedWith < rangeMin) return alwaysFalse(instruction, runner, memState); if (opSign == GT && comparedWith >= rangeMax) return alwaysFalse(instruction, runner, memState); if (opSign == GT && comparedWith < rangeMin) return alwaysTrue(instruction, runner, memState); if (opSign == GE && comparedWith <= rangeMin) return alwaysTrue(instruction, runner, memState); if (opSign == GE && comparedWith > rangeMax) return alwaysFalse(instruction, runner, memState); 

Corresponding issue: https://youtrack.jetbrains.com/issue/IDEA-146950

+3
source

This was brought to my attention about a week ago, so its funny I saw it soon and soon. I looked into it, and this happened already at the beginning of Intellij 10. Several errors were fixed on all updates, but the problem was not fixed clearly.

Here is the link where Jetbrains refers to the error. There are several cases. IDEA-84489

If this bothers you, try suppressing the warning with Alt + Enter while your cursor is over it, and select the option that says "suppress for ..."

+1
source

All Articles