opprop / checker-framework-inference

Inference of pluggable types for Java
6 stars 13 forks source link

`getDefaultAnnotation()` stores the wrong default #404

Open piyush-J opened 2 years ago

piyush-J commented 2 years ago

Original code:

public class Issue160 {
    public static void t1() {
        String s = null;
        if (s != null) {
            s = "abc";
        } else {
            s = "123";
            // return;
        }
        System.out.println(s.toString());
    }
}

Code with default annotation from getDefaultAnnotation():

@NonNull 
public class Issue160 {
    public static void t1() {
        @NonNull String s = null;
        if (s != null) {
            s = "abc";
        } else {
            s = "123";
            // return;
        }
        System.out.println(s.toString());
    }
}

Both the @NonNull annotations are incorrect. Based on the discussion with @zcai1, the method to fetch the default annotation doesn't understand that String s is a local variable.