Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dead code warning in while loop with 2 if's

Tags:

java

dead-code

I can't see why Eclipse gives me a dead code warning for the code in the second if condition:

 boolean frameErreicht = false;
  while (!frameErreicht) {
        String line = reader.readLine();
        if (line.matches("@\\d*")) {
            reader.mark(reader.getLineNumber() - 1);
            reader.setLineNumber(reader.getLineNumber() - 1);
            frameErreicht = true;
        }
        if (line == null)
            throw new IOException("Keine Angaben zu Frames im Eingabestrom");
    }

The jdoc of the readLine() method of LinenumberReader says that it will return null if the end of the stream is reached, so if the match is not found throughout the whole text (line == null) it should throw an exception.
But what's wrong?

like image 371
Big_Chair Avatar asked Dec 03 '22 00:12

Big_Chair


1 Answers

If line had been null, line.matches("@\\d*") would have thrown a NullPointerException

like image 129
Andres Olarte Avatar answered Dec 15 '22 05:12

Andres Olarte