Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[improvement] Enable NullAway gradle checks (#99)
<!-- PR title should start with '[fix]', '[improvement]' or '[break]' if this PR would cause a patch, minor or major SemVer bump. Omit the prefix if this PR doesn't warrant a standalone release. --> ## Before this PR <!-- Describe the problem you encountered with the current state of the world (or link to an issue) and why it's important to fix now. --> The safe-logging library did not explicitly annotate `Arg` and its subtypes, so consumers of this library would receive false-positive warnings when using static analysis checks such as [NullAway](https://github.com/uber/NullAway) or IntelliJ nullability checks, for example the below as seen in palantir/tritium#152 where [use of `UnsafeArg.of` with a `@Nullable` value](https://github.com/palantir/tritium/blob/develop/tritium-core/src/main/java/com/palantir/tritium/event/CompositeInvocationEventHandler.java#L142) is mistakenly flagged: ``` warning: [NullAway] passing @nullable parameter 'context' where @nonnull is required UnsafeArg.of("context", context), ^ ``` ## After this PR <!-- Describe at a high-level why this approach is better. --> Enables [NullAway](https://github.com/uber/NullAway) gradle build checks and appropriately annotates Arg and its subtypes to support proper nullability analysis. <!-- Reference any existing GitHub issues, e.g. 'fixes #000' or 'relevant to #000' --> Relevant to palantir/tritium#152 and supersedes #97 The NullAway checks identified one possible issue in safe-logging's `LoggableExceptionAssert`, and this has been corrected. * Handle null LoggableExceptionAssert arg, addresses NullAway warnings: ``` > Task :preconditions-assertj:compileJava /Volumes/git/safe-logging/preconditions-assertj/src/main/java/com/palantir/logsafe/testing/LoggableExceptionAssert.java:30: warning: [NullAway] initializer method does not guarantee @nonnull field argsAssert is initialized along all control-flow paths (remember to check for exceptions or early returns). public LoggableExceptionAssert(T actual) { ^ (see http://t.uber.com/nullaway ) /Volumes/git/safe-logging/preconditions-assertj/src/main/java/com/palantir/logsafe/testing/LoggableExceptionAssert.java:33: warning: [NullAway] assigning @nullable expression to @nonnull field argsAssert = actual == null ? null : new ArgsAssert(actual.getArgs()); ^ (see http://t.uber.com/nullaway ) 2 warnings ``` Another error-prone warning identified a potential issue with `Arg.equals` implementation * Arg.equals checks isSafeForLogging, addresses EqualsGetClass error-prone finding: ``` > Task :safe-logging:compileJava /Volumes/git/safe-logging/safe-logging/src/main/java/com/palantir/logsafe/Arg.java:51: warning: [EqualsGetClass] Overriding Object#equals in a non-final class by using getClass rather than instanceof breaks substitutability of subclasses. public final boolean equals(Object other) { ^ (see https://errorprone.info/bugpattern/EqualsGetClass) Did you mean 'if (!(other instanceof Arg)) {'? 1 warning ```
- Loading branch information