File: ViewpointAdaptation.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 (51 lines) | stat: -rw-r--r-- 1,661 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Test case for Issue #770
// https://github.com/typetools/checker-framework/issues/770

import org.checkerframework.checker.lock.qual.GuardedBy;

public class ViewpointAdaptation {
    // :: error: (expression.unparsable.type.invalid)
    private final @GuardedBy("a") ViewpointAdaptation f = new ViewpointAdaptation();

    private @GuardedBy("this.lock") ViewpointAdaptation g = new ViewpointAdaptation();

    private final Object lock = new Object();

    private int counter;

    public void method1(final String a) {
        synchronized (a) {
            // The expression "a" from the @GuardedBy annotation
            // on f is not valid at the declaration site of f.
            // :: error: (expression.unparsable.type.invalid)
            f.counter++;
        }
    }

    public void method2() {
        ViewpointAdaptation t = new ViewpointAdaptation();

        // :: error: (assignment.type.incompatible)
        t.g = g; // "t.lock" != "this.lock"

        synchronized (t.lock) {
            // :: error: (lock.not.held)
            g.counter++;
        }
    }

    public void method3() {
        final ViewpointAdaptation t = new ViewpointAdaptation();
        // The type of 'g' is refined from @GuardedByUnknown (the default for
        // a local variable due to CLIMB-to-top semantics) to @GuardedBy("t.g")
        final ViewpointAdaptation g = t.g;
        Object l = t.lock;

        synchronized (l) {
            // Aliasing of lock expressions is not tracked by the Lock Checker.
            // The Lock Checker does not know that l == t.lock
            // :: error: (lock.not.held)
            g.counter++;
        }
    }
}