File: RawTypesUses.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 (57 lines) | stat: -rw-r--r-- 2,035 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
52
53
54
55
56
57
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

public abstract class RawTypesUses {
    class Generic<G extends @Nullable Object> {
        G foo() {
            throw new RuntimeException();
        }
    }

    void foo() {
        Generic<@Nullable String> notRawNullable = new Generic<>();
        // :: error: (assignment.type.incompatible)
        @NonNull Object o1 = notRawNullable.foo();

        Generic rawNullable = new Generic<@Nullable String>();
        // TODO: false negative. See #635.
        //// :: error: (assignment.type.incompatible)
        @NonNull Object o2 = rawNullable.foo();

        Generic<@NonNull String> notRawNonNull = new Generic<>();
        @NonNull Object o3 = notRawNonNull.foo();

        Generic rawNonNull = new Generic<@NonNull String>();
        Generic rawNonNullAlais = rawNonNull;
        // TODO: false negative. See #635.
        //// :: error: (assignment.type.incompatible)
        @NonNull Object o4 = rawNonNull.foo();
        // TODO: false negative. See #635.
        //// :: error: (assignment.type.incompatible)
        @NonNull Object o5 = rawNonNullAlais.foo();
    }

    abstract Generic rawReturn();

    void bar() {
        // :: warning: [unchecked] unchecked conversion
        Generic<@Nullable String> notRawNullable = rawReturn();
        // :: error: (assignment.type.incompatible)
        @NonNull Object o1 = notRawNullable.foo();

        Generic rawNullable = rawReturn();
        // TODO: false negative. See #635.
        //// :: error: (assignment.type.incompatible)
        @NonNull Object o2 = rawNullable.foo();

        // TODO: false negative. See #635.
        //// :: error: (assignment.type.incompatible)
        @NonNull Object o3 = rawReturn().foo();

        Generic local = rawReturn();
        Generic localAlias = local;
        // TODO: false negative. See #635.
        //// :: error: (assignment.type.incompatible)
        @NonNull Object o4 = local.foo();
    }
}