From 1ad304b30c94155502df521bca64eb8f51ec85fc Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Fri, 6 Oct 2017 11:36:10 +0700 Subject: [PATCH] DfaFactType: fixed default range for float/double; tests Fixes test DataFlowRangeAnalysisTest.testLongRangeBasics --- .../codeInspection/dataFlow/DfaFactType.java | 3 +-- .../dataFlow/fixture/LongRangeAnnotation.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaFactType.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaFactType.java index 23488627caa8..8469976a3c38 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaFactType.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaFactType.java @@ -114,9 +114,8 @@ public abstract class DfaFactType extends Key { } } PsiModifierListOwner psiVariable = var.getPsiVariable(); - LongRangeSet fromAnnotation = LongRangeSet.fromAnnotation(psiVariable); LongRangeSet fromType = LongRangeSet.fromType(var.getVariableType()); - return fromType == null ? fromAnnotation : fromAnnotation.intersect(fromType); + return fromType == null ? null : LongRangeSet.fromAnnotation(psiVariable).intersect(fromType); } @Nullable diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/LongRangeAnnotation.java b/java/java-tests/testData/inspection/dataFlow/fixture/LongRangeAnnotation.java index 59d1bc3a54a4..36d3ca034500 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/LongRangeAnnotation.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/LongRangeAnnotation.java @@ -6,6 +6,18 @@ public class LongRangeAnnotation { return new Random().nextInt(100); } + @Nonnegative int x; + @Nonnegative double y; + + void testField() { + if(x < 0) { + System.out.println("Impossible"); + } + if(y < 0) { + System.out.println("Doubles are not supported yet"); + } + } + void testAnnotated() { int value = method(); if(value == 0) {