Skip to content

Remove method-level Atomic annotations. - #56

Merged
cpovirk merged 1 commit into
mainfrom
classatomic
Feb 5, 2024
Merged

cpovirk merged 1 commit into
mainfrom
classatomic

Conversation

@cpovirk

@cpovirk cpovirk commented Feb 5, 2024

Copy link
Copy Markdown
Collaborator

They are unnecessary, troublesome, and probably wrong.

Unnecessary: We don't care about annotations on private and
package-private APIs because users don't interact with them. The only
reason that we have annotations here in the first place is that we we
automatically translated every occurrence of plain <T> to <T extends @Nullable Object> in classes that were already annotated for nullness
in the upstream Checker Framework JDK. But that wasn't necessarily the
right thing to do for private and package-private members, since the
upstream Checker Framework JDK doesn't necessarily annotate those
properly (nor do we). So it's likely that the upstream code "should"
have used <T extends [@NonNull] Object>, which we would then have
automatically translated to <T>, thus avoiding this problem.

Troublesome: The JDK changed its definitions of these methods to no
longer contain a type parameter at all in later JDK versions. As a
result, we try to behave as if an annotation is present in a location
that does not exist. That leads to problems, as discussed in Google bug
323609832.

Probably wrong: I haven't looked much, but my guess is that a
ReflectionData instance is associated with a Class<T> object. So,
just as we declare Class with a non-nullable type parameter, we'd
likely want to do the same with ReflectionData. If we were to do that
(not that I bothered in this PR, though I could), then the <T extends @Nullable Object> on the methods would create an out-of-bounds type
argument.

They are unnecessary, troublesome, and probably wrong.

Unnecessary: We don't care about annotations on private and
package-private APIs because users don't interact with them. The only
reason that we have annotations here in the first place is that we we
automatically translated every occurrence of plain `<T>` to `<T extends
@nullable Object>` in classes that were already annotated for nullness
in the upstream Checker Framework JDK. But that wasn't necessarily the
right thing to do for private and package-private members, since the
upstream Checker Framework JDK doesn't necessarily annotate those
properly (nor do we). So it's likely that the upstream code "should"
have used `<T extends [@nonnull] Object>`, which we would then have
automatically translated to `<T>`, thus avoiding this problem.

Troublesome: The JDK changed its definitions of these methods to no
longer contain a type parameter at all in later JDK versions. As a
result, we try to behave as if an annotation is present in a location
that does not exist. That leads to problems, as discussed in Google bug
323609832.

Probably wrong: I haven't looked much, but my guess is that a
`ReflectionData` instance is associated with a `Class<T>` object. So,
just as we declare `Class` with a non-nullable type parameter, we'd
likely want to do the same with `ReflectionData`. If we were to do that
(not that I bothered in this PR, though I could), then the `<T extends
@nullable Object>` on the methods would create an out-of-bounds type
argument.

@wmdietl wmdietl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

@cpovirk
cpovirk merged commit a1ecc8e into main Feb 5, 2024
@cpovirk
cpovirk deleted the classatomic branch February 5, 2024 20:45
@cpovirk cpovirk mentioned this pull request Dec 17, 2024
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 this pull request may close these issues.

2 participants