openhab / static-code-analysis

Maven tooling for static code analysis
https://www.openhab.org/
Other
32 stars 21 forks source link

Don't check inner classes for missing @NonNullByDefault #383

Closed wborn closed 4 years ago

wborn commented 4 years ago

As a result there will still be a warning for annotating the outer class when @NonNullByDefault is missing. It is redundant to annotate inner classes when outer classes are annotated. The compiler generates warnings when both outer and inner classes are annotated.

Fixes #351


Example:

example

wborn commented 4 years ago

I will check if it still does the other checks, e.g. warning when @NonNull is used. If it no longer does that we need to modify the check to only skip the @NonNullByDefault check on inner classes.

wborn commented 4 years ago

The checkInnerUnits seems to work as advertised in the JavaDocs and only enables/disables checking for @NonNullByDefault on inner classes:

https://github.com/openhab/static-code-analysis/blob/1d154f8b149eca630146502253b36e369be8837f/custom-checks/checkstyle/src/main/java/org/openhab/tools/analysis/checkstyle/NullAnnotationsCheck.java#L54-L59

Looks like Eclipse also checks and warns for such issues nowadays :+1: :

test

wborn commented 4 years ago

This change will also reduce the number of SAT NullAnnotationsCheck findings since it will only warn about missing @NonNullByDefault at most once per file.

The NullAnnotationsCheck findings are:

Project Before After Delta
openhab-core 1162 997 165
openhab-addons 4209 3712 497