Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce correct type-use annotation locations for nested types #1026

Open
msridhar opened this issue Aug 24, 2024 · 1 comment · May be fixed by #1045
Open

Enforce correct type-use annotation locations for nested types #1026

msridhar opened this issue Aug 24, 2024 · 1 comment · May be fixed by #1045
Assignees

Comments

@msridhar
Copy link
Collaborator

Type-use nullability annotations on a nested type need to be written on the inner-most type (so instead of writing @Nullable A.B, write A.@Nullable B; see here). Consider this example:

import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
class SampleQualified {
    class A {
        class B {}
    }
    @Nullable A.B f;
}

This example currently passes NullAway, but on the JSpecify reference checker yields an error:

SampleQualified.java:12: error: [nullness] illegal location for annotation: outer types are always non-null. To annotate the inner type, write `Foo.@Nullable Bar` instead of `@Nullable Foo.Bar`.
    @Nullable A.B f;
                  ^
1 error

As part of #708, we should update NullAway to also require that type-use annotations be written in the correct location for nested types, and issue an error otherwise. This new treatment should be applied independent of the JSpecifyMode flag. The previous treatment of type-use annotations should be preserved if the LegacyAnnotationLocations flag is set to true. And a declaration @Nullable annotation should continue to be treated as applying to the inner-most type (whether the JSpecifyMode flag is set or not).

@msridhar
Copy link
Collaborator Author

Related: #706

And see also: #708 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants