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 113055 Details for
Bug 248040
[compiler][null] Fake Potential Null Pointer Access triggered by check against null.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Different test cases showing where the problem happens and where it doesn't.
PotentialNullPointerAccess.java (text/plain), 3.17 KB, created by
Rodolfo Federico Gamarra
on 2008-09-20 01:08:39 EDT
(
hide
)
Description:
Different test cases showing where the problem happens and where it doesn't.
Filename:
MIME Type:
Creator:
Rodolfo Federico Gamarra
Created:
2008-09-20 01:08:39 EDT
Size:
3.17 KB
patch
obsolete
>package org.eclipse.test; >public class PotentialNullPointerAccess { > public static String notNull() { > return "a"; > } > public static boolean doNothing(boolean b){ > return false; > } > /* > * Different test cases for Potential Null Pointer Access. > */ > public static void caseA() { > String a = notNull(); > boolean isNotNull = a != null; > if(isNotNull) { > /* > * Wrong: Fake potential null pointer access warning. > * Potential null pointer access: The variable a may be null at this location > * > * Despite we're checking to be different from null, we get the warning. > */ > a.toString(); > } > } > public static void caseB() { > String a = notNull(); > if(a != null) { > /* > * 0k: No potential null pointer access warning. > */ > a.toString(); > } > } > public static void caseC() { > String a = notNull(); > /* > * 0k: No potential null pointer access warning, the analyzer can't > * guess what the outcome would be from the function. > */ > a.toString(); > } > public static void caseD() { > String a = notNull(); > // We know for sure it won't be null. > boolean isNotNull = true; > if(isNotNull) { > /* > * 0k: No potential null pointer access warning. > */ > a.toString(); > } > } > public static void caseE() { > String a = notNull(); > if(doNothing(a != null)) { > /* > * Wrong: Fake potential null pointer access warning. > * The use of a != null is wrapped inside a function call, the > * outcome can be anything. > */ > a.toString(); > } > } > public static void caseF() { > String a = notNull(); > doNothing(a != null); > if(true) { > /* > * Wrong: Fake potential null pointer access warning. > * Note that the call with a != null as parameter is unrelated to the condition. > */ > a.toString(); > } > } > public static void caseG() { > String a = notNull(); > doNothing(false); > if(true) { > /* > * 0k: No potential null pointer access warning. > */ > a.toString(); > } > } > public static void caseH() { > String a = notNull(); > if(true) { > /* > * 0k: No potential null pointer access warning. > * Taking into account caseF one could expect this case to give > * the warning as well. In both cases the call, with the comparison > * as parameter is unrelated to the if block. > */ > a.toString(); > } > doNothing(a != null); > } > public static void caseI() { > String a = "a"; > doNothing(a != null); > if(true) { > /* > * 0k: No potential null pointer access warning. > * Despite the check, as a is clearly not null, no warning > * is issued. > */ > a.toString(); > } > } >}
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 Raw
Actions:
View
Attachments on
bug 248040
: 113055