DataFlowInspectionAncientTest converted to LightCodeInsightFixtureTestCase

This commit is contained in:
Tagir Valeev
2018-09-14 13:37:35 +07:00
parent 8b29ee7675
commit 1508f0a28b
153 changed files with 674 additions and 2046 deletions
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>9</line>
<description>Passing null argument to parameter annotated as @NotNull</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>5</line>
<description>Array access &lt;code&gt;path[0]&lt;/code&gt; will produce &lt;code&gt;NullPointerException&lt;/code&gt;</description>
</problem>
</problems>
@@ -1,9 +0,0 @@
public class Test {
public String foo(String[] path) {
if (path != null) return null;
String p = path[0];
return "";
}
}
@@ -1,63 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>6</line>
<method>
<name>void main(String[] args)</name>
<display_name>main(String[])</display_name>
<package>&lt;default&gt;</package>
<class>
<name>DoubleTrouble</name>
<display_name>DoubleTrouble</display_name>
</class>
</method>
<description>Condition &lt;code&gt;b == Double.NaN&lt;/code&gt; is always &lt;code&gt;false&lt;/code&gt;.</description>
</problem>
<problem>
<file>Test.java</file>
<line>11</line>
<method>
<name>void main(String[] args)</name>
<display_name>main(String[])</display_name>
<package>&lt;default&gt;</package>
<class>
<name>DoubleTrouble</name>
<display_name>DoubleTrouble</display_name>
</class>
</method>
<description>Condition &lt;code&gt;Float.NaN != Float.NaN&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt;.</description>
</problem>
<problem>
<file>Test.java</file>
<line>18</line>
<method>
<name>void main(String[] args)</name>
<display_name>main(String[])</display_name>
<package>&lt;default&gt;</package>
<class>
<name>DoubleTrouble</name>
<display_name>DoubleTrouble</display_name>
</class>
</method>
<description>Condition &lt;code&gt;Double.NaN == a&lt;/code&gt; is always &lt;code&gt;false&lt;/code&gt;.</description>
</problem>
<problem>
<file>Test.java</file>
<line>19</line>
<method>
<name>void main(String[] args)</name>
<display_name>main(String[])</display_name>
<package>&lt;default&gt;</package>
<class>
<name>DoubleTrouble</name>
<display_name>DoubleTrouble</display_name>
</class>
</method>
<description>Condition &lt;code&gt;b == a&lt;/code&gt; is always &lt;code&gt;false&lt;/code&gt;.</description>
</problem>
</problems>
@@ -1,22 +0,0 @@
public class DoubleTrouble {
public static void main(String[] args) {
{
Double a = Double.NaN;
double b = a;//Double.NaN;
if (b == Double.NaN) {
;
}
}
if (Float.NaN != Float.NaN) {
}
{
double a = Double.NaN;
double b = Double.NaN;
if (Double.NaN == a) {}
if (b == a) {}
}
}
}
@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>8</line>
<description>Condition 'e == null' is always false</description>
</problem>
<problem>
<file>Test.java</file>
<line>11</line>
<description>Condition 'e instanceof FileNotFoundException' is always false</description>
</problem>
</problems>
@@ -1,16 +0,0 @@
import java.io.*;
public class Foo {
public void foo() {
try {
throw new EOFException("aaa");
} catch (Exception e) {
if (e == null) {
System.out.println("Can't be here.");
}
if (e instanceof FileNotFoundException) {
System.out.println("Can't be here.");
}
}
}
}
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>9</line>
<description>Method invocation 'foo' may produce NullPointerException</description>
</problem>
<problem>
<file>Test.java</file>
<line>10</line>
<description>Method invocation 'foo' may produce NullPointerException</description>
</problem>
<problem>
<file>Test.java</file>
<line>10</line>
<description>Method invocation 'foo' may produce NullPointerException</description>
</problem>
</problems>
@@ -1,14 +0,0 @@
import org.jetbrains.annotations.Nullable;
public class Foo {
@Nullable Foo foo() {
return null;
}
public void bar() {
if (foo() != null &&
foo().foo() != null &&
foo().foo().foo() != null) {
}
}
}
@@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>4</line>
<method>
<name>void f()</name>
<display_name>f()</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Test</name>
<display_name>Test</display_name>
</class>
</method>
<description>Condition &lt;code&gt;L == 5&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt;</description>
</problem>
<problem>
<file>Test.java</file>
<line>9</line>
<method>
<name>void f()</name>
<display_name>f()</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Test</name>
<display_name>Test</display_name>
</class>
</method>
<description>Condition &lt;code&gt;l == 0f&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt;</description>
</problem>
<problem>
<file>Test.java</file>
<line>14</line>
<method>
<name>void f()</name>
<display_name>f()</display_name>
<package>&lt;default&gt;</package>
<class>
<name>Test</name>
<display_name>Test</display_name>
</class>
</method>
<description>Condition &lt;code&gt;c == 1L&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt;</description>
</problem>
</problems>
@@ -1,19 +0,0 @@
public class Test {
void f() {
Long L = 5L;
if (L == 5) {
;
}
long l = 0;
if (l == 0f) {
;
}
char c = 1;
if (c == 1L) {
;
}
}
}
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>18</line>
<description>Argument 'obj' might be null</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>4</line>
<description>Dereference of 'path' may produce NullPointerException</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
public class Test {
public String foo(String[] path) {
if (path != null) return null;
for (String p: path) {}
return "";
}
}
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>GenericInstanceof.java</file>
<line>8</line>
<description>Condition is always true</description>
</problem>
</problems>
@@ -1,12 +0,0 @@
class Generic<T> {
Generic() {}
}
class Test {
void foo () {
Generic g = new Generic ();
if (g instanceof Generic<String>) {
return;
}
}
}
@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>IDEADEV10489.java</file>
<line>10</line>
<description>Method invocation 'length' may produce NullPointerException</description>
</problem>
<problem>
<file>IDEADEV10489.java</file>
<line>8</line>
<description>Method invocation 'length' may produce NullPointerException</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>9</line>
<description>Condition 'foo != null' is always 'true'</description>
</problem>
</problems>
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>14</line>
<description>'length' may produce 'NullPointerException'</description>
</problem>
<problem>
<file>Npe.java</file>
<line>18</line>
<description>'length' may produce 'NullPointerException'</description>
</problem>
<problem>
<file>Npe.java</file>
<line>27</line>
<description>'length' may produce 'NullPointerException'</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>4</line>
<description>Condition 'test' at the left side is always 'true'</description>
</problem>
</problems>
@@ -1,6 +0,0 @@
class TestGenericsInstanceof {
public void foo(Object o) {
boolean test = true;
test &= o.hashCode() > 3;
}
}
@@ -1,86 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>AndAssign.java</file>
<line>19</line>
<description>Condition is always true</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>26</line>
<description>Condition is always false</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>33</line>
<description>Condition is always false</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>40</line>
<description>Condition is always false</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>47</line>
<description>Condition is always true</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>54</line>
<description>Condition is always true</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>61</line>
<description>Condition is always true</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>68</line>
<description>Condition is always false</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>17</line>
<description>left always true</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>24</line>
<description>left always true</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>31</line>
<description>left always false</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>38</line>
<description>left always false</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>45</line>
<description>left always true</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>52</line>
<description>left always true</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>59</line>
<description>left always false</description>
</problem>
<problem>
<file>AndAssign.java</file>
<line>66</line>
<description>left always false</description>
</problem>
</problems>
@@ -1,72 +0,0 @@
public class AndAssign {
public void foo(boolean result, Object acc) {
result &= verify(result ? acc : null);
}
public boolean verify(Object o) {
System.out.println(o);
return true;
}
public void positives() {
boolean t = true;
boolean f = false;
boolean r;
r = t;
r &= t; // Always true
if (r) { // Always true
System.out.println("foo");
}
r = t;
r &= f; // Always true
if (r) { // Always false
System.out.println("foo");
}
r = f;
r &= t; // Always false
if (r) { // Always false
System.out.println("foo");
}
r = f;
r &= f; // Always false
if (r) { // Always false
System.out.println("foo");
}
r = t;
r |= t // Always true
if (r) { // Always true
System.out.println("foo");
}
r = t;
r |= f // Always true
if (r) { // Always true
System.out.println("foo");
}
r = f;
r |= t // Always false
if (r) { // Always true
System.out.println("foo");
}
r = f;
r |= f // Always false
if (r) { // Always false
System.out.println("foo");
}
}
}
@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>NoWarnings.java</file>
<line>9</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Constant conditions &amp; exceptions</problem_class>
<description>Condition &lt;code&gt;i == 1&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt; when reached</description>
</problem>
</problems>
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Foo.java</file>
<line>10</line>
<description>Condition 'o instanceof B' is always false</description>
</problem>
</problems>
@@ -1,14 +0,0 @@
class A {
}
class B extends A {
}
class C {
void foo(Object o) {
if (o instanceof A || o instanceof B) {
System.out.println("Something");
}
}
}
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>10</line>
<description>Condition 'o == null' is always false</description>
</problem>
</problems>
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>9</line>
<description>Passing null argument to parameter annotated as @NotNull</description>
</problem>
</problems>
@@ -1,11 +0,0 @@
import org.jetbrains.annotations.NotNull;
public class Npe {
Object foo(@NotNull Object o) {
return o;
}
void bar() {
Object o = foo(null); // null should not be passed here.
}
}
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>5</line>
<description>Condition 'o == null' is always false</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>14</line>
<description>Argument 'nullable()' might be null</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>7</line>
<description>'hashCode' may produce NullPointerException</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>6</line>
<description>Method invocation &lt;code&gt;bar&lt;/code&gt; may produce &lt;code&gt;NullPointerException&lt;/code&gt;</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>6</line>
<description>null is returned</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>8</line>
<description>Expression 'res' might evaluate to null but is returned by the method declared as @NotNull</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>14</line>
<description>Argument '(Object)nullable()' might be null</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Npe.java</file>
<line>15</line>
<description>Argument 'o' might be null</description>
</problem>
</problems>
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>6</line>
<description>Condition 'c == null' is always false</description>
</problem>
</problems>
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>14</line>
<description>Condition '!a &amp;&amp; b' always false</description>
</problem>
<problem>
<file>Test.java</file>
<line>14</line>
<description>Condition '!a' always false</description>
</problem>
</problems>
@@ -1,16 +0,0 @@
class Test
{
class Test
{
public void x()
{
boolean a = false;
boolean b = true;
do
{
a = true;
}
while( !a && b );
}
}}
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Finally.java</file>
<line>9</line>
<description>Method invocation 'hashCode' may produce NullPointerException</description>
</problem>
</problems>
@@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>3</line>
<description>Condition 't instanceof Test' is redundant</description>
</problem>
<problem>
<file>Test.java</file>
<line>9</line>
<description>Condition 't instanceof Test' always true</description>
</problem>
<problem>
<file>Test.java</file>
<line>14</line>
<description>Condition 'foo(null) instanceof Test' is redundant</description>
</problem>
</problems>
@@ -1,17 +0,0 @@
public class Test {
public Test foo(Test t) {
if (t instanceof Test) { // redundant instanceof error here. t can be null
foo(null);
}
}
public Object bar(Test t) {
if (t == null) return;
if (t instanceof Test) { // always true error here. t can't be null
foo(null);
}
if (bar(null) instanceof Test) return null; // no error here.
if (foo(null) instanceof Test) return null; // redundant instanceof error here. foo(null) can be null
return null;
}
}
@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>NullTest.java</file>
<line>6</line>
<description>Dereference of 't' will produce NullPointerException</description>
</problem>
</problems>
@@ -1,9 +0,0 @@
public class NullTest {
int m;
void f() {};
public void x() {
NullTest t = null;
t.m = 12;
t.f();
}
}
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems />
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>72</line>
<description>Method invocation &lt;code&gt;length&lt;/code&gt; may produce &lt;code&gt;NullPointerException&lt;/code&gt;</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>10</line>
<description>Dereference of 'getE()' may produce 'NullPointerException'</description>
</problem>
</problems>
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>9</line>
<description>'foo() != null' is always true</description>
</problem>
</problems>
@@ -1,4 +1,4 @@
public class Test {
class Test {
public Test(String s) { }
public Test foo(String path) {
@@ -0,0 +1,8 @@
class Test {
public void foo(boolean x, boolean y, boolean z) {
boolean r = true;
<warning descr="Condition 'r' at the left side of assignment expression is always 'true'. Can be simplified">r</warning> &= x;
r &= y;
r &= z;
}
}
@@ -1,11 +1,11 @@
import org.jetbrains.annotations.*;
public class Test {
class Test {
private static void foo(@NotNull String smth) {
}
public static void main(String[] args) {
String s = args[0];
foo(null);
foo(<warning descr="Passing 'null' argument to parameter annotated as @NotNull">null</warning>);
}
}
@@ -0,0 +1,9 @@
class Test {
public String foo(String[] path) {
if (path != null) return null;
String p = <warning descr="Array access 'path[0]' will produce 'NullPointerException'">path[0]</warning>;
return "";
}
}
@@ -0,0 +1,119 @@
class Auto {
void f(int k) {
Integer i = 0;
Integer j=0;
if (<warning descr="Condition 'i==j' is always 'true'">i==j</warning>) {
}
Integer j2 = 1;
if (<warning descr="Condition 'i==j2' is always 'false'">i==j2</warning>) {
}
if (<warning descr="Condition 'i==0' is always 'true'">i==0</warning>) {
}
if (<warning descr="Condition 'i==1' is always 'false'">i==1</warning>) {
}
//////////////////
Integer big1 = 333;
Integer big2= 333;
if (<warning descr="Condition 'big1==333' is always 'true'">big1==333</warning>) {
}
if (<warning descr="Condition '333 == big2' is always 'true'">333 == big2</warning>) {
}
if (<warning descr="Condition '333==333' is always 'true'">333==333</warning>) {
}
if (<warning descr="Condition 'big1==big2' is always 'false'">big1==big2</warning>) {
}
int prim = big1;
if (<warning descr="Condition 'prim==big2' is always 'true'">prim==big2</warning>) {
}
if (<warning descr="Condition 'big1 == 0' is always 'false'">big1 == 0</warning>) {
}
if (<warning descr="Condition 'big1 == 332' is always 'false'">big1 == 332</warning>) {
}
Character c = 1234;
if (<warning descr="Condition 'c==1234' is always 'true'">c==1234</warning>) {
}
if (<warning descr="Condition 'c==124' is always 'false'">c==124</warning>) {
}
c = 1;
if (<warning descr="Condition 'c==1234' is always 'false'">c==1234</warning>) {
}
if (<warning descr="Condition 'c==c' is always 'true'">c==c</warning>) {
}
Character c2 = 1;
if (<warning descr="Condition 'c==c2' is always 'true'">c==c2</warning>) {
}
}
}
class aaa {
int a;
int b;
void canBeStatic(int x) {
for (int i=0;i<10;i++) {
a = i;
}
a = 4;
if (<warning descr="Condition 'a == 5' is always 'false'">a == 5</warning>) {
}
}
void f(int p) {
{
int i = 1;
Integer i1 = i;
Integer i2 = i;
if (<warning descr="Condition 'i1 == i2' is always 'true'">i1 == i2</warning>) {
}
}
{
int i = p;
Integer i1 = i;
Integer i2 = i;
if (i1 == i2) {
}
}
}
}
class UsesDoubleAndFloat {
void f() {
double dd = 10.0;
Double r = dd;
Double r1 = dd;
System.out.println("(r==r1) is "+(r==r1)); // should report??
Double r2 = 10.0;
Double r3 = 10.0;
System.out.println("(r2==r3) is "+(<warning descr="Condition 'r2==r3' is always 'false' when reached">r2==r3</warning>));
float fd = 10.0f;
Float fr = fd;
Float fr1 = fd;
System.out.println("(r==r1) is "+(fr==fr1)); // should report??
Float fr2 = 10.0f;
Float fr3 = 10.0f;
System.out.println("(r2==r3) is "+(<warning descr="Condition 'fr2==fr3' is always 'false' when reached">fr2==fr3</warning>));
}
}
@@ -0,0 +1,22 @@
class DoubleTrouble {
public static void main(String[] args) {
{
Double a = Double.NaN;
double b = a;//Double.NaN;
if (<warning descr="Condition 'b == Double.NaN' is always 'false'">b == Double.NaN</warning>) {
;
}
}
if (<warning descr="Condition 'Float.NaN != Float.NaN' is always 'true'">Float.NaN != Float.NaN</warning>) {
}
{
double a = Double.NaN;
double b = Double.NaN;
if (<warning descr="Condition 'Double.NaN == a' is always 'false'">Double.NaN == a</warning>) {}
if (<warning descr="Condition 'b == a' is always 'false'">b == a</warning>) {}
}
}
}
@@ -15,7 +15,7 @@ public class aaa {
o.equals(o);
}
o.equals(o);
o.<warning descr="Method invocation 'equals' may produce 'NullPointerException'">equals</warning>(o);
if (i == 3) {
System.out.println("");
@@ -37,15 +37,15 @@ public class aaa {
//System.exit(0);
switch(i) {
case 1: System.out.println("1 not reachable"); break;
case 2: System.out.println("2 not reachable"); break;
<warning descr="Switch label 'case 1:' is unreachable">case 1:</warning> System.out.println("1 not reachable"); break;
<warning descr="Switch label 'case 2:' is unreachable">case 2:</warning> System.out.println("2 not reachable"); break;
case 6: System.out.println("6 reachable"); break;
case 5: System.out.println("5 reachable"); break;
default: System.out.println("Default not reachable"); break;
}
int j = 0;
for (; i < 5; i++, j++) {}
for (; <warning descr="Condition 'i < 5' is always 'false'">i < 5</warning>; i++, j++) {}
}
void canBeStatic() {
@@ -57,7 +57,7 @@ public class aaa {
}
}
for (int i = 0; i < null; i++) {
for (int i = 0; <error descr="Operator '<' cannot be applied to 'int', 'null'">i < null</error>; i++) {
a = i;
this.a = i;
}
@@ -68,8 +68,8 @@ public class aaa {
a = 4;
}
if (a != null && a instanceof aaa) {
if (true) {
if (<warning descr="Condition 'a != null' is always 'true'">a != null</warning> && a instanceof aaa) {
if (<warning descr="Condition is always true">true</warning>) {
//a = new aaa();
}
}
@@ -0,0 +1,16 @@
import java.io.*;
class Foo {
public void foo() {
try {
throw new EOFException("aaa");
} catch (Exception e) {
if (<warning descr="Condition 'e == null' is always 'false'">e == null</warning>) {
System.out.println("Can't be here.");
}
if (<warning descr="Condition 'e instanceof FileNotFoundException' is always 'false'">e instanceof FileNotFoundException</warning>) {
System.out.println("Can't be here.");
}
}
}
}
@@ -9,7 +9,7 @@ public class Cce {
Object o = getObject();
if (o instanceof A) {
B b = (B) o;
B b = (<warning descr="Casting 'o' to 'B' may produce 'ClassCastException'">B</warning>) o;
}
}
@@ -1,3 +1,5 @@
import java.util.Random;
public class CheckedExceptionDominance {
private static class CheckedException extends Exception {}
@@ -0,0 +1,14 @@
import org.jetbrains.annotations.Nullable;
class Foo {
@Nullable Foo foo() {
return null;
}
public void bar() {
if (foo() != null &&
foo().<warning descr="Method invocation 'foo' may produce 'NullPointerException'">foo</warning>() != null &&
foo().<warning descr="Method invocation 'foo' may produce 'NullPointerException'">foo</warning>().<warning descr="Method invocation 'foo' may produce 'NullPointerException'">foo</warning>() != null) {
}
}
}
@@ -1,9 +1,9 @@
public class Test {
class Test {
private static final int CONST = 3/2 + 0*1;
public void foo() {
int i = 0;
int j = 2 + (CONST) - 6/2;
if (i == j) {
if (<warning descr="Condition 'i == j' is always 'true'">i == j</warning>) {
}
}
}
@@ -0,0 +1,19 @@
class Test {
void f() {
Long L = 5L;
if (<warning descr="Condition 'L == 5' is always 'true'">L == 5</warning>) {
;
}
long l = 0;
if (<warning descr="Condition 'l == 0f' is always 'true'">l == 0f</warning>) {
;
}
char c = 1;
if (<warning descr="Condition 'c == 1L' is always 'true'">c == 1L</warning>) {
;
}
}
}
@@ -1,6 +1,6 @@
import org.jetbrains.annotations.*;
public class TestNullableIntervening // See http://www.jetbrains.net/jira/browse/IDEA-2845
class TestNullableIntervening
{
@Nullable Object obj;
@@ -15,7 +15,7 @@ public class TestNullableIntervening // See http://www.jetbrains.net/jira/brow
if (obj != null) {
// Method intervening, might change obj; should have warning (OK)
obj = foo();
notnull(obj);
notnull(<warning descr="Argument 'obj' might be null">obj</warning>);
}
}
@@ -1,6 +1,6 @@
import org.jetbrains.annotations.Nullable;
public class Test {
class Test {
@Nullable public final String o;
public Test(String q) { o = q; }
@@ -0,0 +1,8 @@
class Test {
public String foo(String[] path) {
if (path != null) return null;
for (String p: <warning descr="Dereference of 'path' may produce 'NullPointerException'">path</warning>) {}
return "";
}
}
@@ -1,4 +1,4 @@
public class Npe {
class Npe {
Object foo(Object[] objs) {
boolean skip = true;
for (Object o : objs) {
@@ -0,0 +1,12 @@
class Generic<T> {
Generic() {}
}
class Test {
void foo () {
Generic g = new Generic ();
if (<warning descr="Condition 'g instanceof Generic<String>' is always 'true'">g instanceof <error descr="Illegal generic type for instanceof">Generic<String></error></warning>) {
return;
}
}
}
@@ -5,9 +5,9 @@ class IDEADEV10489 {
String s = getS();
if (s != null) s.length();
if (foo()) {
int[] i1 = new int [s.length()];
int[] i1 = new int [s.<warning descr="Method invocation 'length' may produce 'NullPointerException'">length</warning>()];
} else if (foo()) {
int[] i2 = new int [] {s.length()};
int[] i2 = new int [] {s.<warning descr="Method invocation 'length' may produce 'NullPointerException'">length</warning>()};
} else if (foo()) {
int[][] i3 = new int [(s = "").length()][s.length()];
} else{
@@ -6,7 +6,7 @@ class Test {
void foo() {
String[] data = new String[] {"abs", "def"};
for (@NotNull String foo: data) {
assert foo != null; // Condition always true
assert <warning descr="Condition 'foo != null' is always 'true'">foo != null</warning>; // Condition always true
}
}
}
@@ -1,4 +1,5 @@
import org.jetbrains.annotations.*;
import java.io.IOException;
class Foo {
public void x() throws IOException {
@@ -11,11 +11,11 @@ class Test {
void test(Collection<String> foos) {
Test t = new Test();
final int i = t.getString("foo").length();
final int i = t.getString("foo").<warning descr="Method invocation 'length' may produce 'NullPointerException'">length</warning>();
System.out.println("i = " + i);
for (String foo : foos) {
final int j = t.getString(foo).length();
final int j = t.getString(foo).<warning descr="Method invocation 'length' may produce 'NullPointerException'">length</warning>();
System.out.println("i = " + j);
}
}
@@ -24,7 +24,7 @@ class Test {
Test t = new Test();
for (Iterator<String> iterator = foos.iterator(); iterator.hasNext();) {
final int i = getString(iterator.next()).length();
final int i = getString(iterator.next()).<warning descr="Method invocation 'length' may produce 'NullPointerException'">length</warning>();
System.out.println("i = " + i);
}
}
@@ -0,0 +1,6 @@
class TestGenericsInstanceof {
public void foo(Object o) {
boolean test = true;
<warning descr="Condition 'test' at the left side of assignment expression is always 'true'. Can be simplified">test</warning> &= o.hashCode() > 3;
}
}
@@ -0,0 +1,72 @@
public class AndAssign {
public void foo(boolean result, Object acc) {
result &= verify(result ? acc : null);
}
public boolean verify(Object o) {
System.out.println(o);
return true;
}
public void positives() {
boolean t = true;
boolean f = false;
boolean r;
r = t;
<warning descr="Condition 'r' at the left side of assignment expression is always 'true'. Can be simplified">r</warning> &= t; // Always true
if (<warning descr="Condition 'r' is always 'true'">r</warning>) { // Always true
System.out.println("foo");
}
r = t;
<warning descr="Condition 'r' at the left side of assignment expression is always 'true'. Can be simplified">r</warning> &= f; // Always true
if (<warning descr="Condition 'r' is always 'false'">r</warning>) { // Always false
System.out.println("foo");
}
r = f;
<warning descr="Condition 'r' at the left side of assignment expression is always 'false'. Can be simplified">r</warning> &= t; // Always false
if (<warning descr="Condition 'r' is always 'false'">r</warning>) { // Always false
System.out.println("foo");
}
r = f;
<warning descr="Condition 'r' at the left side of assignment expression is always 'false'. Can be simplified">r</warning> &= f; // Always false
if (<warning descr="Condition 'r' is always 'false'">r</warning>) { // Always false
System.out.println("foo");
}
r = t;
<warning descr="Condition 'r' at the left side of assignment expression is always 'true'. Can be simplified">r</warning> |= t<error descr="';' expected"> </error> // Always true
if (<warning descr="Condition 'r' is always 'true'">r</warning>) { // Always true
System.out.println("foo");
}
r = t;
<warning descr="Condition 'r' at the left side of assignment expression is always 'true'. Can be simplified">r</warning> |= f<error descr="';' expected"> </error> // Always true
if (<warning descr="Condition 'r' is always 'true'">r</warning>) { // Always true
System.out.println("foo");
}
r = f;
<warning descr="Condition 'r' at the left side of assignment expression is always 'false'. Can be simplified">r</warning> |= t<error descr="';' expected"> </error> // Always false
if (<warning descr="Condition 'r' is always 'true'">r</warning>) { // Always true
System.out.println("foo");
}
r = f;
<warning descr="Condition 'r' at the left side of assignment expression is always 'false'. Can be simplified">r</warning> |= f<error descr="';' expected"> </error> // Always false
if (<warning descr="Condition 'r' is always 'false'">r</warning>) { // Always false
System.out.println("foo");
}
}
}
@@ -1,12 +1,12 @@
import java.util.*;
public class NoWarnings {
class NoWarnings {
public void f() {
int i = 1;
boolean b = true;
while (true) {
if (b && i == 1) {
if (b && <warning descr="Condition 'i == 1' is always 'true' when reached">i == 1</warning>) {
b = false;
}
else {
@@ -1,4 +1,4 @@
public abstract class NoWarnings {
abstract class NoWarnings {
public void f() {
boolean A = false;
boolean B = false;
@@ -1,6 +1,6 @@
import org.jetbrains.annotations.*;
public class Test {
class Test {
public @Nullable String foo;
public void test() {
@@ -1,6 +1,6 @@
import org.jetbrains.annotations.Nullable;
public class NoWarnings {
class NoWarnings {
int f(@Nullable String value) {
value = value == null ? "" : value;
return value.hashCode();
@@ -13,7 +13,7 @@ public class Inst {
if (a instanceof B) {
A aa =(A) a;
if (a instanceof A) {
if (<warning descr="Condition 'a instanceof A' is always 'true'">a instanceof A</warning>) {
System.out.println("HeHe");
}
System.out.println(aa);
@@ -22,7 +22,7 @@ public class Inst {
public void x1() {
Object a = new Object();
if (a instanceof B) {
if (<warning descr="Condition 'a instanceof B' is always 'false'">a instanceof B</warning>) {
A aa =(A) a;
if (a instanceof A) {
System.out.println("HeHe");
@@ -0,0 +1,14 @@
class A {
}
class B extends A {
}
class C {
void foo(Object o) {
if (o instanceof A || <warning descr="Condition 'o instanceof B' is always 'false' when reached">o instanceof B</warning>) {
System.out.println("Something");
}
}
}
@@ -1,7 +1,7 @@
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
public class TestNPEafterNew {
class TestNPEafterNew {
@Nullable Object[] arr;
void test(@NotNull Object[] notnull) {
arr = notnull;
@@ -1,7 +1,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Npe {
class Npe {
void bar() {
final @NotNull Object o = call();
if (o == null) {}
@@ -1,12 +1,12 @@
import org.jetbrains.annotations.NotNull;
public class Npe {
class Npe {
@NotNull Object foo() {
return new Object();
}
void bar() {
Object o = foo();
if (o == null) System.out.println("Can't be");
if (<warning descr="Condition 'o == null' is always 'false'">o == null</warning>) System.out.println("Can't be");
}
}
@@ -0,0 +1,11 @@
import org.jetbrains.annotations.NotNull;
class Npe {
Object foo(@NotNull Object o) {
return o;
}
void bar() {
Object o = foo(<warning descr="Passing 'null' argument to parameter annotated as @NotNull">null</warning>); // null should not be passed here.
}
}
@@ -1,8 +1,8 @@
import org.jetbrains.annotations.NotNull;
public class Npe {
class Npe {
Object foo(@NotNull Object o) {
if (o == null) {
if (<warning descr="Condition 'o == null' is always 'false'">o == null</warning>) {
// Should not get there.
}
return o;

Some files were not shown because too many files have changed in this diff Show More