...
This noncompliant code example casts the value of type int
returned by the read()
method directly to a value of type char
, which is then compared with -1 in an attempt to detect the end of stream. This conversion leaves the value of c
as 0xffff
(e.g., Character.MAX_VALUE
) instead of -1. Consequently, the test for the end of stream never evaluates to true
(because char
type is unsigned and the value of c
is 0-extended to 0x0000FFFF
).
Code Block | ||
---|---|---|
| ||
FileReader in; // initialize stream char c; while ((c = (char) in.read()) != -1) { // ... } |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0d122810bfba83a4-e5e2d598-423f450d-be86a932-c816b5b4a855f6fb74a2d530"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | Class | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="079a30461e342676-ce54f648-4e6947ce-aecb9e69-f4d73b30f94fda906a600762"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [§4.2 | http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.2] "Primitive Types and Values" | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d4e2f1443b130a75-5478009d-4f9e4cc6-b8519b27-54482145e8ed81257a97584e"><ac:plain-text-body><![CDATA[ | [[Pugh 2008 | AA. Bibliography#Pugh 08]] | "Waiting for the end" | ]]></ac:plain-text-body></ac:structured-macro> |
...