File: NullnessStubfileMerge.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 (45 lines) | stat: -rw-r--r-- 1,575 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
// warning: StubParser: Method thisMethodIsNotReal(String) not found in type java.lang.String
// warning: StubParser: Type not found: java.lang.NotARealClass
// warning: StubParser: Type not found: not.real.NotARealClassInNotRealPackage

import org.checkerframework.checker.nullness.qual.*;

/*
 * This test reads two stub files:
 * tests/nullness-stubfile/stubfile1.astub
 * tests/nullness-stubfile/stubfile2.astub
 *
 * The annotations on the methods are merged such that reading the two
 * stub files is equavlent to the following stubfile:
 *
public final class  String {
     public @Nullable String intern();
     public @NonNull String substring(@Nullable int beginIndex) @Nullable;
     String(@Nullable String arg0);
     void getChars(@Nullable int arg0, @NonNull int arg1, @NonNull char @NonNull [] arg2, @NonNull int arg3) @NonNull;
}
*/
public class NullnessStubfileMerge {
    @Nullable String nullString = null;
    @NonNull String nonNull = "Hello!";

    void method() {
        // below fails because of stub file overruling annotated JDK
        // :: error: (type.argument.type.incompatible)
        java.util.List<@NonNull String> l;

        // :: error: (assignment.type.incompatible)
        @NonNull String error1 = nonNull.intern();

        nonNull.substring('!');

        @NonNull String y = nonNull.substring('!');

        char[] nonNullChars = {'1', '1'};
        char[] nullChars = null;
        nonNull.getChars(1, 1, nonNullChars, 1);

        // :: error: (argument.type.incompatible)
        nonNull.getChars(1, 1, nullChars, 1);
    }
}