Search code examples
javadead-code

Dead code warning in while loop with 2 if's


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?


Solution

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