Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

These methods are often used to read a byte or character from a stream. Unfortunately many programmers prematurely convert the resulting int back to a byte or char before checking whether they have reached the end of the stream (signaled by a return value of -1). Programs must check for end of stream (e.g., -1) before narrowing the return value to a byte or char.

This guideline rule applies to any InputStream or Reader subclass that provide an implementation of the read() method. This guideline rule is a specific instance of NUM15-J. Ensure conversions of numeric types to narrower types do not result in lost or misinterpreted data.

...

FindBugs version 1.3.9 can detect violations of this guideline rule with the INT: Bad comparison of nonnegative value with negative constant detector.

...

Search for vulnerabilities resulting from the violation of this guideline rule on the CERT website.

Related Guidelines

...