The result of this call to readLine is not null checked
193 public void run() {
194 String str;
195 try {
196 str = nis.readLine();197 while (!str.equals("End")) {
198 ta.append(str);
199 str = nis.readLine();
The result of this call to readLine is not null checked
74 public void run() {
75 String str;
76 try {
77 str = nis.readLine(); 78 while (!str.equals("End")) {
79 ta.append(str);
80 str = nis.readLine();
Description
The result of invoking readLine()
is read without checking to see if it is null.
Bad Practice
If there are no more lines of text to read, readLine
will return null and dereferencing that will generate a null pointer exception.
String a = bufReader.readLine();
int b = a.length; // Will throw an NPE if a is null.
Recommended
String a = bufReader.readLine();
if (a == null) {
// do something....
}
Unless you are absolutely confident that this will not happen (though it is a sensible thing to do even then), check if the result is null and perform an appropriate action if it is.
References
- SpotBugs - NP_DEREFERENCE_OF_READLINE_VALUE