readLine
result is read without a null check JAVA-E0220193 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();
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();
The result of invoking readLine()
is read without checking to see if it is null.
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.
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.