Article:
 |
|
Custom PMD Rules
|
| Subject: |
|
Null check for an object |
| Date: |
|
2006-03-21 22:45:33 |
| From: |
|
PravinD
|
|
|
|
please help me in writing the rule for the following scenario:
Before invoking any method of an object, a null check should be done.
Eg:
String str1 = null;
String str2 = "ASP";
str2 = str1.toUpperCase(); // Which will throw NullPointerException.
So I have to ensure that this line is in the if check. Like,
String str1 = null;
String str2 = "ASP";
if(str1 != null)
{
str2 = str1.toUpperCase();
}
Any help would be appreciated. Which would be better a Java rule or XPATH rule?
Thanks,
Meena
|
Showing messages 1 through 1 of 1.
-
Null check for an object
2006-03-23 05:47:29
tcopeland
[View]
These are a good question... would you mind posting them to the PMD "Open Discussion" forum?
http://sourceforge.net/forum/forum.php?forum_id=188192
That way more folks will see your questions and be able to comment. Thanks!
Yours,
Tom
Using PMD? Get the book! http://pmdapplied.com/