Skip to content

Commit

Permalink
Prepare our code for when our nullness checker recognizes that `asEle…
Browse files Browse the repository at this point in the history
…ment` can return `null`.

RELNOTES=n/a
PiperOrigin-RevId: 683828218
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Oct 9, 2024
1 parent 3c0b3cc commit 3c44741
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions common/src/main/java/com/google/auto/common/Overrides.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.auto.common;

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;

import com.google.common.base.Preconditions;
Expand Down Expand Up @@ -432,7 +433,8 @@ ExecutableElement methodFromSuperinterfaces(TypeElement in, ExecutableElement me
private @Nullable TypeElement superclass(TypeElement type) {
TypeMirror sup = type.getSuperclass();
if (sup.getKind() == TypeKind.DECLARED) {
return MoreElements.asType(typeUtils.asElement(sup));
// asElement returns non-null for DECLARED types.
return MoreElements.asType(requireNonNull(typeUtils.asElement(sup)));
} else {
return null;
}
Expand All @@ -441,7 +443,11 @@ ExecutableElement methodFromSuperinterfaces(TypeElement in, ExecutableElement me
private ImmutableList<TypeElement> superinterfaces(TypeElement type) {
ImmutableList.Builder<TypeElement> types = ImmutableList.builder();
for (TypeMirror sup : type.getInterfaces()) {
types.add(MoreElements.asType(typeUtils.asElement(sup)));
/*
* All interfaces implemented/extended are DECLARED types, for which asElement returns
* non-null.
*/
types.add(MoreElements.asType(requireNonNull(typeUtils.asElement(sup))));
}
return types.build();
}
Expand Down

0 comments on commit 3c44741

Please sign in to comment.