readLine
result is read without a null check JAVA-E0220285 String name = br.readLine();
286 if (name.equals("EOF"))
287 return;
288 String paClass = br.readLine();289 String position = br.readLine();
290 String groupName = br.readLine();
291 if (paClass.equals("First")) {
282 try (var br = new BufferedReader(fr)) {
283 while (br.ready()) {
284 for (int i = 0; i < 4; ++i) {
285 String name = br.readLine();286 if (name.equals("EOF"))
287 return;
288 String paClass = br.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.