Skip to content

Commit

Permalink
Annotate RecordComponent. (#92)
Browse files Browse the repository at this point in the history
`getGenericSignature()` is not documented well, but I noticed that
`getGenericType()` compares the result of `getGenericSignature()`
against `null`, so that got me to verify that it can in fact return
`null`:

```
public class RecordComponentGenericSignature {
  record Rec(String s) {}

  public static void main(String[] args) {
    System.out.println(Rec.class.getRecordComponents()[0].getGenericSignature());
  }
}
```
  • Loading branch information
cpovirk authored Oct 7, 2024
1 parent a93551a commit b8b7d1c
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

package java.lang.reflect;

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

import jdk.internal.access.SharedSecrets;
import sun.reflect.annotation.AnnotationParser;
import sun.reflect.annotation.TypeAnnotation;
Expand All @@ -46,6 +49,7 @@
* @jls 8.10 Record Classes
* @since 16
*/
@NullMarked
public final class RecordComponent implements AnnotatedElement {
// declaring class
private Class<?> clazz;
Expand Down Expand Up @@ -91,7 +95,7 @@ public Class<?> getType() {
*
* @jvms 4.7.9.1 Signatures
*/
public String getGenericSignature() {
public @Nullable String getGenericSignature() {
return signature;
}

Expand Down Expand Up @@ -178,7 +182,7 @@ public Method getAccessor() {
* @throws NullPointerException {@inheritDoc}
*/
@Override
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
public <T extends Annotation> @Nullable T getAnnotation(Class<T> annotationClass) {
Objects.requireNonNull(annotationClass);
return annotationClass.cast(declaredAnnotations().get(annotationClass));
}
Expand Down

0 comments on commit b8b7d1c

Please sign in to comment.