Skip to content

Commit dc9cf0e

Browse files
authored
Handle records in targetTypeMatches (#1061)
Fixes #1059
1 parent 8f4b928 commit dc9cf0e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/RecordTests.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,27 @@ public void recordDeconstructionPatternSwitchCase() {
252252
"}")
253253
.doTest();
254254
}
255+
256+
@Test
257+
public void issue1059() {
258+
defaultCompilationHelper
259+
.addSourceLines(
260+
"BarEntity.java",
261+
"package com.uber;",
262+
"import org.jspecify.annotations.NonNull;",
263+
"import org.jspecify.annotations.Nullable;",
264+
"public class BarEntity {",
265+
" public interface Identifiable<ID> {",
266+
" @Nullable",
267+
" ID id();",
268+
" }",
269+
" public static class Id {}",
270+
" public record NameChanged(BarEntity.Id id, Class<BarEntity> type) implements Identifiable<@NonNull Id> {",
271+
" public NameChanged(BarEntity.Id id) {",
272+
" this(id, BarEntity.class);",
273+
" }",
274+
" }",
275+
"}")
276+
.doTest();
277+
}
255278
}

nullaway/src/main/java/com/uber/nullaway/NullabilityUtil.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,13 @@ private static boolean targetTypeMatches(Symbol sym, TypeAnnotationPosition posi
370370
// on other types in the signature (e.g. `class Foo extends Bar<@A Baz> {}`).
371371
return false;
372372
default:
373-
throw new AssertionError("unsupported element kind " + sym.getKind() + " symbol " + sym);
373+
// Compare with toString() to preserve compatibility with JDK 11
374+
if (sym.getKind().toString().equals("RECORD")) {
375+
// Records are treated like classes
376+
return false;
377+
} else {
378+
throw new AssertionError("unsupported element kind " + sym.getKind() + " symbol " + sym);
379+
}
374380
}
375381
}
376382

0 commit comments

Comments
 (0)