| 1 |
// Test case for issue #1248: |
| 2 |
// https://github.com/typetools/checker-framework/issues/1248 |
| 3 |
|
| 4 |
import java.util.function.Predicate; |
| 5 |
import org.checkerframework.checker.nullness.qual.NonNull; |
| 6 |
import org.checkerframework.checker.nullness.qual.Nullable; |
| 7 |
|
| 8 |
public class RefinedLocalInLambda { |
| 9 |
|
| 10 |
public static void main(String[] args) { |
| 11 |
printIntegersGreaterThan(10); |
| 12 |
} |
| 13 |
|
| 14 |
public static void printIntegersGreaterThan(@Nullable Integer limit) { |
| 15 |
// :: error: (unboxing.of.nullable) |
| 16 |
printIntegersWithPredicate(i -> i > limit); // type-checking fails |
| 17 |
if (limit == null) { |
| 18 |
return; |
| 19 |
} |
| 20 |
printIntegersWithPredicate(i -> i > limit); // type-checking succeeds |
| 21 |
@NonNull Integer limit2 = limit; |
| 22 |
printIntegersWithPredicate(i -> i > limit2); // type-checking succeeds |
| 23 |
Integer limit3 = limit; |
| 24 |
printIntegersWithPredicate(i -> i > limit3); // type-checking succeeds |
| 25 |
} |
| 26 |
|
| 27 |
public static void printIntegersWithPredicate(Predicate<Integer> tester) { |
| 28 |
for (int i = 0; i < 100; i++) { |
| 29 |
if (tester.test(i)) { |
| 30 |
System.out.println(i); |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
} |