Skip to content

AddNullMarkedToPackageInfo should also report absent packages #5261

@JarvisCraft

Description

@JarvisCraft

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:

if (thePackage.exists()) {
    if (!thePackage.isAnnotated(NullMarked.class)) {
        reportError("No @NullMarked on packages %s", thePackage);
    }
}

Suggested:

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions