File: RefinedLocalInLambda.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (34 lines) | stat: -rw-r--r-- 1,170 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
// Test case for issue #1248:
// https://github.com/typetools/checker-framework/issues/1248

import java.util.function.Predicate;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

public class RefinedLocalInLambda {

    public static void main(String[] args) {
        printIntegersGreaterThan(10);
    }

    public static void printIntegersGreaterThan(@Nullable Integer limit) {
        // :: error: (unboxing.of.nullable)
        printIntegersWithPredicate(i -> i > limit); // type-checking fails
        if (limit == null) {
            return;
        }
        printIntegersWithPredicate(i -> i > limit); // type-checking succeeds
        @NonNull Integer limit2 = limit;
        printIntegersWithPredicate(i -> i > limit2); // type-checking succeeds
        Integer limit3 = limit;
        printIntegersWithPredicate(i -> i > limit3); // type-checking succeeds
    }

    public static void printIntegersWithPredicate(Predicate<Integer> tester) {
        for (int i = 0; i < 100; i++) {
            if (tester.test(i)) {
                System.out.println(i);
            }
        }
    }
}