Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Nullaway #988

Merged
merged 5 commits into from
Jan 25, 2024
Merged

Enable Nullaway #988

merged 5 commits into from
Jan 25, 2024

Conversation

ash211
Copy link
Contributor

@ash211 ash211 commented Jan 21, 2024

Fixes #987

Before this PR

Nullaway is not enabled, and null handling isn't verified by that plugin.

After this PR

==COMMIT_MSG==
Enable Nullaway
==COMMIT_MSG==

Fix flagged issues by adding @Nullable and handling nulls better with Optional.ofNullable

Possible downsides?

NullAway might fail future PRs more often; it can be fiddly in requirements that tend to be largely unimportant in practice (like that Exception messages can be null).

@changelog-app
Copy link

changelog-app bot commented Jan 21, 2024

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Enable Nullaway

Check the box to generate changelog(s)

  • Generate changelog entry

@ash211 ash211 requested a review from CRogers January 22, 2024 16:05
@ash211 ash211 marked this pull request as ready for review January 22, 2024 16:06
@ash211 ash211 requested a review from schlosna January 24, 2024 22:46
schlosna
schlosna previously approved these changes Jan 25, 2024
Copy link
Contributor

@schlosna schlosna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, thanks for the cleanup!

@@ -130,7 +132,7 @@ private int formatFiles(CommandLineOptions parameters, JavaFormatterOptions opti
}
}

for (Map.Entry<Path, Future<String>> result : results.entrySet()) {
for (Entry<Path, Future<String>> result : results.entrySet()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intentional? I'm surprised this didn't trigger error-prone BadImport

Suggested change
for (Entry<Path, Future<String>> result : results.entrySet()) {
for (Map.Entry<Path, Future<String>> result : results.entrySet()) {

Copy link
Contributor Author

@ash211 ash211 Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, looks like Entry was removed from the BadImport list 3 years ago, but my brain has already been conditioned to qualify Entry.

google/error-prone@38a0e4b

@@ -215,10 +220,10 @@ public static CommandLineOptions processArgs(String... args) throws UsageExcepti
try {
parameters = CommandLineOptionsParser.parse(Arrays.asList(args));
} catch (IllegalArgumentException e) {
throw new UsageException(e.getMessage());
throw new UsageException(Optional.ofNullable(e.getMessage()).orElse("null"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to change this, but in other types of hot paths java.until.Objects.requireNonNullElse can avoid the Optional allocation

Suggested change
throw new UsageException(Optional.ofNullable(e.getMessage()).orElse("null"));
throw new UsageException(Objects. requireNonNullElse(e.getMessage(), "null"));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing -- I've needed this before and its good to know a way to do this without the allocation

@policy-bot policy-bot bot dismissed schlosna’s stale review January 25, 2024 05:20

Invalidated by push of bb18ad9

@ash211 ash211 requested a review from schlosna January 25, 2024 05:21
@bulldozer-bot bulldozer-bot bot merged commit 83fc06c into develop Jan 25, 2024
7 checks passed
@bulldozer-bot bulldozer-bot bot deleted the aash/enable-nullaway branch January 25, 2024 16:16
eholmer pushed a commit that referenced this pull request Oct 21, 2024
This PR adds support for `switch` statements where a `case` has a guard clause.

See Issue #983

Fixes #988

COPYBARA_INTEGRATE_REVIEW=google/google-java-format#988 from TheCK:master 4771486db7d8aab84eb4ecf8e68af2612d0c2b5c
PiperOrigin-RevId: 588913297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apply baseline's NullAway on this repo
3 participants