| Article: |
Custom PMD Rules | |
| Subject: | Few More Rules Pls | |
| Date: | 2005-04-11 06:05:45 | |
| From: | tcopeland | |
|
Response to: Few More Rules Pls
|
||
|
Hi Pravin -
|
||
Showing messages 1 through 2 of 2.
-
Null check for an object
2006-03-21 23:04:26 PravinD [View]
-
Few More Rules Pls
2005-04-11 07:27:43 PravinD [View]
Oh okie! Shall check the thread in the pmd forums. Once again, Thanks mate!
Regards,
Pravin. D



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?