dfa: take into account known variable values when handling number comparisons (IDEA-126446)

This commit is contained in:
peter
2014-07-18 09:14:06 +02:00
parent 1aa6e7ac2b
commit 28870690fd
4 changed files with 74 additions and 24 deletions
@@ -20,6 +20,11 @@
<line>49</line>
<description>Switch label 'case 2:' is unreachable</description>
</problem>
<problem>
<file>CaseAndNpe.java</file>
<line>56</line>
<description>Condition &lt;code&gt;i &lt; 5&lt;/code&gt; is always &lt;code&gt;false&lt;/code&gt;</description>
</problem>
<problem>
<file>CaseAndNpe.java</file>
<line>80</line>
@@ -0,0 +1,16 @@
import java.util.Arrays;
class Test {
int[] mIndex = null;
int mSize = 0;
void indexValues() {
float loadFactor = mIndex == null ? 1.f : ((float) mSize) / ((float) mIndex.length);
if (loadFactor < 0.25f || 0.75f <= loadFactor) {
mIndex = new int[mSize * 2];
}
mIndex[0] = -1;
}
}
@@ -251,6 +251,8 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testUseInferredContracts() { doTest(); }
public void testNumberComparisonsWhenValueIsKnown() { doTest(); }
public void testParametersAreNonnullByDefault() {
myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}");
myFixture.addClass("package javax.annotation; public @interface ParametersAreNullableByDefault {}");