File: Issue524.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 (39 lines) | stat: -rw-r--r-- 1,593 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
// Test case for Issue 524:
// https://github.com/typetools/checker-framework/issues/524

import java.util.concurrent.locks.ReentrantLock;
import org.checkerframework.checker.lock.qual.GuardedBy;

// WARNING: this test is nondeterministic, and has already been
// minimized - if you modify it by removing what appears to be
// redundant code, it may no longer reproduce the issue or provide
// coverage for the issue after a fix for the issue has been made.

// About the nondeterminism:
// The desired behavior, with the fix for issue 524 in place, is for the test to type check without
// issuing any warnings.
// (Notice that there are no expected warnings below.)
// However even without a fix for issue 524 in place, the test sometimes type checks.
// Unfortunately a test case that always fails to typecheck using a Checker Framework build
// prior to the fix for issue 524 has not been found.
class Issue524 {
    class MyClass {
        public Object field;
    }

    void testLocalVariables() {
        @GuardedBy({}) ReentrantLock localLock = new ReentrantLock();

        {
            // :: error: (lock.expression.not.final)
            @GuardedBy("localLock") MyClass q = new MyClass();
            localLock.lock();
            localLock.lock();
            // Without a fix for issue 524 in place, the error lock.not.held
            // (unguarded access to field, variable or parameter 'q' guarded by 'localLock') is
            // issued for the following line.
            // :: error: (expression.unparsable.type.invalid)
            q.field.toString();
        }
    }
}