File: ReadyReadLine.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (33 lines) | stat: -rw-r--r-- 970 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.dataflow.qual.Pure;

class ReadyReadLine {

    void m(MyBufferedReader buf) throws Exception {
        if (buf.ready()) {
            String line = buf.readLine();
            line.toString();
        }

        if (buf.readLine() != null) {
            // :: error: (dereference.of.nullable)
            buf.readLine().toString();
        }
    }
}

// this is a replication of the JDK BufferedReader (with only the relevant methods)
class MyBufferedReader {
    public @Nullable String readLine() throws Exception {
        return null;
    }

    @EnsuresNonNullIf(expression = "readLine()", result = true)
    @Pure
    public boolean ready() throws Exception {
        // don't bother with implementation.
        // :: error: (contracts.conditional.postcondition.not.satisfied)
        return true;
    }
}