File: TestConcurrentSemantics2.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 (30 lines) | stat: -rw-r--r-- 901 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
package chapter;

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

class TestConcurrentSemantics2 {
    final Object a = new Object();
    final Object b = new Object();

    @GuardedBy("a") Object o;

    void method() {
        o = null;
        // Assume the following happens:
        //  * Context switch to a different thread.
        //  * bar() is called on the other thread.
        //  * Context switch back to this thread.
        // o is no longer null and an assignment.type.incompatible error should be issued.
        // :: error: (assignment.type.incompatible)
        @GuardedBy("b") Object o2 = o;
    }

    void bar() {
        o = new Object();
    }

    // Test that field assignments do not cause their type to be refined:
    @GuardedBy("a") Object myObject1 = null;
    // :: error: (assignment.type.incompatible)
    @GuardedBy("b") Object myObject2 = myObject1;
}