diff --git a/java/java-impl/src/com/intellij/codeInspection/OverflowingLoopIndexInspection.java b/java/java-impl/src/com/intellij/codeInspection/OverflowingLoopIndexInspection.java index a4b7dd8dd73d..2ac1bb3a8422 100644 --- a/java/java-impl/src/com/intellij/codeInspection/OverflowingLoopIndexInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/OverflowingLoopIndexInspection.java @@ -135,9 +135,9 @@ public class OverflowingLoopIndexInspection extends AbstractBaseJavaLocalInspect boolean negative = number.longValue() < 0; IElementType op = assignment.getOperationTokenType(); if (conditionType == ConditionType.VarGreater) { - return op == JavaTokenType.PLUSEQ || (op == JavaTokenType.MINUSEQ && negative); + return (op == JavaTokenType.PLUSEQ && !negative) || (op == JavaTokenType.MINUSEQ && negative); } else { - return op == JavaTokenType.MINUSEQ || (op == JavaTokenType.PLUSEQ && negative); + return (op == JavaTokenType.MINUSEQ && !negative) || (op == JavaTokenType.PLUSEQ && negative); } } return false; diff --git a/java/java-tests/testData/inspection/overflowingLoop/OverflowingLoop.java b/java/java-tests/testData/inspection/overflowingLoop/OverflowingLoop.java index 4a30f5fc7a34..c156c62fdfbd 100644 --- a/java/java-tests/testData/inspection/overflowingLoop/OverflowingLoop.java +++ b/java/java-tests/testData/inspection/overflowingLoop/OverflowingLoop.java @@ -30,7 +30,7 @@ public class OverflowingLoop { } void minusEqAddNegative(int s) { - for (int i = s; i > 12; i += -12) { + for (int i = s; i > 12; i += -12) { System.out.println(i + 23); } } @@ -61,4 +61,10 @@ public class OverflowingLoop { i+= 100; } } + + void minusEqMinus(int s) { + for (int i = 0; i < 10; i -=- 1) { + System.out.println("asdsakdj"); + } + } }