Skip to content

getDefaultAnnotation() stores the wrong default #404

Description

@piyush-J

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions