### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java,v retrieving revision 1.95 diff -u -r1.95 ConditionalExpression.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 15 Jul 2009 17:42:43 -0000 1.95 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java 17 Jul 2010 15:50:15 -0000 @@ -318,6 +318,17 @@ if (ifTrueNullStatus == ifFalseNullStatus) { return ifTrueNullStatus; } + // is there a chance of null? -> potentially null + switch (ifTrueNullStatus) { + case FlowInfo.NULL: + case FlowInfo.POTENTIALLY_NULL: + return FlowInfo.POTENTIALLY_NULL; + } + switch (ifFalseNullStatus) { + case FlowInfo.NULL: + case FlowInfo.POTENTIALLY_NULL: + return FlowInfo.POTENTIALLY_NULL; + } return FlowInfo.UNKNOWN; // cannot decide which branch to take, and they disagree } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java,v retrieving revision 1.95 diff -u -r1.95 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 16 Mar 2010 14:36:08 -0000 1.95 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 17 Jul 2010 15:50:30 -0000 @@ -738,7 +738,7 @@ // other path: use a tainted unknown expression status; does not seem to cope well // with o = (o == null ? new Object() : o) // TODO (maxime) https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 -public void _test0034_conditional_expression() { +public void test0034_conditional_expression() { this.runNegativeTest( new String[] { "X.java", @@ -749,12 +749,65 @@ " o.toString();\n" + " }\n" + "}\n"}, - "----------\n" + - "1. ERROR in X.java (at line 4)\n" + - " o.toString();\n" + - " ^\n" + - "The variable o may be null\n" + - "----------\n"); + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"); +} +//null analysis -- conditional expression +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 +//variant with constant condition +public void test0034_conditional_expression_2() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo() {\n" + + " Object o = false ? null : new Object();\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} +//null analysis -- conditional expression +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 +//variant with dependency between condition and expression - LocalDeclaration +// TODO(stephan) cannot analyse this flow dependency +public void _test0034_conditional_expression_3() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo(Object u) {\n" + + " if (u == null) {}\n" + //taint + " Object o = (u == null) ? new Object() : u;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} +//null analysis -- conditional expression +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 +//variant with dependency between condition and expression - Assignment +//TODO(stephan) cannot analyse this flow dependency +public void _test0034_conditional_expression_4() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo(Object u) {\n" + + " if (u == null) {}\n" + //taint + " Object o;\n" + + " o = (u == null) ? new Object() : u;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); } // null analysis -- conditional expression