biddyweb / checker-framework

Automatically exported from code.google.com/p/checker-framework
Other
0 stars 1 forks source link

Bogus Warning in lambda expression #367

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the Null Checker on the class below
package test;

class Test {
    static void test(Iterable<? extends Thread> threads) {
        threads.forEach(thread -> System.out.println(thread));
    }
}

What is the expected output? What do you see instead?
Expected: no warning
Actual: test\Test.java:5: error: [lambda.param.type.incompatible] incompatible 
parameter types in lambda expression.
        threads.forEach(thread -> System.out.println(thread));
                        ^
  found   : ? extends @Initialized @NonNull Thread
  required: capture#214 of ? extends java.lang.Thread extends @Initialized @NonNull Thread
1 error

What version of the product are you using? On what operating system?
1.8.6/Windows 8/Java 8

Original issue reported on code.google.com by ClovisSe...@gmail.com on 28 Sep 2014 at 12:21

GoogleCodeExporter commented 9 years ago
Another valid Java class containing lambda expressions and for which the Null 
Checker issues bogus warnings:

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

abstract class Test {
    abstract <@NonNull T> void test(T obj, Function<T, Integer> f);

    void m() {
        test("", s -> 1);
    }
}

        test("", s -> 1);
                 ^
  found   : @NonNull T extends @Initialized @NonNull Object
  required: @Initialized @NonNull String

        test("", s -> 1);
                 ^
  found   : T extends Object
  required: String

Original comment by ClovisSe...@gmail.com on 4 Oct 2014 at 9:35

GoogleCodeExporter commented 9 years ago
Hi Clovis,

Thanks for the report! I have reproduced both of these and added test cases.

The first requires improvements to our handling of wildcard capture.

The second is fixed in our private typevariable-improvements repository which 
should be merged into mainline within the next couple of releases.

Original comment by mcart...@cs.washington.edu on 26 Jan 2015 at 6:43