Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 151153 Details for
Bug 291418
Missing "redundant null check" warning in foreach.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
proposed fix v0.5 + regression test
Redundantnullbug2.txt (text/plain), 5.45 KB, created by
Ayushman Jain
on 2009-11-03 01:34:09 EST
(
hide
)
Description:
proposed fix v0.5 + regression test
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2009-11-03 01:34:09 EST
Size:
5.45 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java,v >retrieving revision 1.44 >diff -u -r1.44 LoopingFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 7 Mar 2009 01:08:10 -0000 1.44 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 3 Nov 2009 06:32:42 -0000 >@@ -405,6 +405,9 @@ > } else { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >+ } else if (this.upstreamNullFlowInfo.isDefinitelyNonNull(local) && !flowInfo.isPotentiallyNull(local)) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291418 >+ flowInfo.markAsDefinitelyNonNull(local); >+ recordNullReference(local, reference, checkType); > } else if (! flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { > if (flowInfo.isPotentiallyNonNull(local)) { > recordNullReference(local, reference, CAN_ONLY_NON_NULL | checkType & CONTEXT_MASK); >#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.81 >diff -u -r1.81 NullReferenceTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 27 Aug 2009 15:26:58 -0000 1.81 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 3 Nov 2009 06:32:49 -0000 >@@ -10130,4 +10130,86 @@ > "Potential null pointer access: The variable o1 may be null at this location\n" + > "----------\n"); > } >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=291418 >+// Test to verify that redundant null checks are properly reported in all loops >+public void testBug291418() { >+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "class X {\n" + >+ " void foo(int[] argArray) {\n" + >+ " int[] array = {2};\n" + >+ " int[] collectionVar = {1,2};\n" + >+ " if(argArray == null) return;" + >+ " for(int x:collectionVar) {\n" + >+ " if (collectionVar == null);\n" + // collectionVar cannot be null here >+ " if (array == null);\n" + //array is not null here >+ " if (argArray == null);\n" + //argArray cannot be null here >+ " }\n" + >+ " int count = 0;\n" + >+ " do {\n" + >+ " count++;\n" + >+ " if (array == null);\n" + //array is not null here >+ " if (argArray == null);\n" + //argArray cannot be null here >+ " } while (count<10);\n" + >+ " for (int i=0; i<2; i++) {\n" + >+ " if (array == null);\n" + //array is not null here >+ " if (argArray == null);\n" + //argArray cannot be null here >+ " }\n" + >+ " while (true) {\n" + >+ " if (array == null);\n" + //array is not null here >+ " if (argArray == null);\n" + //argArray cannot be null here >+ " }\n" + >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 6)\n" + >+ " if (collectionVar == null);\n" + >+ " ^^^^^^^^^^^^^\n" + >+ "Null comparison always yields false: The variable collectionVar cannot be null at this location\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 7)\n" + >+ " if (array == null);\n" + >+ " ^^^^^\n" + >+ "Null comparison always yields false: The variable array cannot be null at this location\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 8)\n" + >+ " if (argArray == null);\n" + >+ " ^^^^^^^^\n" + >+ "Null comparison always yields false: The variable argArray cannot be null at this location\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 13)\n" + >+ " if (array == null);\n" + >+ " ^^^^^\n" + >+ "Null comparison always yields false: The variable array cannot be null at this location\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 14)\n" + >+ " if (argArray == null);\n" + >+ " ^^^^^^^^\n" + >+ "Null comparison always yields false: The variable argArray cannot be null at this location\n" + >+ "----------\n" + >+ "6. ERROR in X.java (at line 17)\n" + >+ " if (array == null);\n" + >+ " ^^^^^\n" + >+ "Null comparison always yields false: The variable array cannot be null at this location\n" + >+ "----------\n" + >+ "7. ERROR in X.java (at line 18)\n" + >+ " if (argArray == null);\n" + >+ " ^^^^^^^^\n" + >+ "Null comparison always yields false: The variable argArray cannot be null at this location\n" + >+ "----------\n" + >+ "8. ERROR in X.java (at line 21)\n" + >+ " if (array == null);\n" + >+ " ^^^^^\n" + >+ "Null comparison always yields false: The variable array cannot be null at this location\n" + >+ "----------\n" + >+ "9. ERROR in X.java (at line 22)\n" + >+ " if (argArray == null);\n" + >+ " ^^^^^^^^\n" + >+ "Null comparison always yields false: The variable argArray cannot be null at this location\n" + >+ "----------\n"); >+ } >+} > } >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 291418
:
150909
|
151153
|
151789