Commit c27f3f4
authored
Substitute inferred
Fixes #1444
In certain cases, like the test from #1444 added here, `javac` adds a
`@Nullable` annotation to a type incorrectly as part of its inference.
Here, for a call from the test:
```java
@NullMarked
public class Test {
static class DefaultConfiguration {
final @nullable Stream<? extends String> children;
}
final Stream<? extends String> children;
Test(DefaultConfiguration configuration) {
// relevant call
this.children = notNull(configuration.children, "children must not be null");
}
public static <T> T notNull(@nullable T object, String message) {
throw new RuntimeException("todo");
}
}
```
`javac`s inferred type for the return of the `notNull` call matches the
inferred parameter type exactly, `@Nullable Stream<...>`. But, when
applying JSpecify rules, the return cannot be `@Nullable`. To fix this,
add inferred `@NonNull` qualifiers along with `@Nullable` when doing a
substitution inside a type.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Simplified printing of error/unknown generic types to show only the
simple type name.
* Improved type-variable substitution so inferred nullability is applied
for both nullable and non-null cases.
* **Tests**
* Added/updated tests covering generic method type inference and
JSpecify/Nullability behaviors (includes a new scenario for issue1444).
<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->@NonNull types for generic method inference (#1445)1 parent fc6d956 commit c27f3f4
3 files changed
Lines changed: 52 additions & 13 deletions
File tree
- nullaway/src
- main/java/com/uber/nullaway/generics
- test/java/com/uber/nullaway/jspecify
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
92 | 99 | | |
93 | 100 | | |
94 | 101 | | |
| |||
Lines changed: 14 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
239 | 241 | | |
240 | 242 | | |
241 | 243 | | |
| |||
Lines changed: 31 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
428 | | - | |
| 428 | + | |
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| |||
1498 | 1498 | | |
1499 | 1499 | | |
1500 | 1500 | | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
1501 | 1531 | | |
1502 | 1532 | | |
1503 | 1533 | | |
| |||
0 commit comments