`AddNullMarkedToPackageInfo` should also report absent packages
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
# Problem
There is an experimental `AddNullMarkedToPackageInfo` bug pattern which reports `package-info.java` files which do not have `@NullMarked` applied to them.
It does help detect the issue of forgetting to add `@NullMarked` to the package, but in our experience a more common problem is forgetting to create package-info itself and thus marking it with `@NullMarked` which is currently *not* caught by the checker.
# Solution
The suggestion is to also handle this scenario, probably also allowing the package to be explicitly `@NullUnmarked` so that there still is an escape hatch for unannotated packages.
## Pseudo-code
Currently:
```java
if (thePackage.exists()) {
if (!thePackage.isAnnotated(NullMarked.class)) {
reportError("No @NullMarked on packages %s", thePackage);
}
}
```
Suggested:
```java
if (thePackage.exists()) {
if (!thePackage.isAnnotated(NullMarked.class)
&& !thePackage.isAnnotated(NullUnmarked.class)) {
reportError("No @NullMarked or @NullUnmarked on packages %s", thePackage);
}
} else {
reportError("No package info %s", thePackage);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.