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

Replace Validate checks #3589

Closed
wants to merge 11 commits into from
Closed

Conversation

ybw0014
Copy link
Contributor

@ybw0014 ybw0014 commented Jun 11, 2022

Description

As #3586 said, replace all Validate checks with Precondition.

Proposed changes

  • Replace all Validate.notNull(Object, String) with Preconditions.checkArgument(Object, String). (Changing to Preconditions.checkNotNull will throw NullPointerException)

Related Issues (if applicable)

Resolves #3586

Checklist

  • I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • I followed the existing code standards and didn't mess up the formatting.
  • I did my best to add documentation to any public classes or methods I added.
  • I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • I added sufficient Unit Tests to cover my code.

@ybw0014
Copy link
Contributor Author

ybw0014 commented Jun 11, 2022

Not sure about how you would like to replace Validate.noNullElements, so discuss it here or https://discord.com/channels/565557184348422174/565570276038017044/985310097955758081.

@ybw0014 ybw0014 marked this pull request as ready for review June 11, 2022 23:14
@ybw0014 ybw0014 requested review from a team as code owners June 11, 2022 23:14
Validate.noNullElements(handlers, "You cannot add any 'null' ItemHandler!");
Preconditions.checkArgument(handlers != null && handlers.length > 0, "You cannot add zero handlers...");
for (ItemHandler handler : handlers) {
Preconditions.checkArgument(handler != null, "You cannot add any 'null' ItemHandler!");
Copy link
Member

Choose a reason for hiding this comment

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

This should definitely be a util method.

I don't think it warrants needing to be in dough so I'd just add it under our utils package.

@ybw0014 ybw0014 marked this pull request as draft June 12, 2022 02:35
@ybw0014 ybw0014 marked this pull request as ready for review June 12, 2022 02:35
Copy link
Member

@TheBusyBiscuit TheBusyBiscuit left a comment

Choose a reason for hiding this comment

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

I really find Preconditions.checkNotNull better semantic wise but it's a shame that it throws an NPE...

I was really hoping we could avoid writing our own util for it, but it really seems like Preconditions doesn't cover our use cases too well...

Perhaps a Validate class should be added to dough-common then... or Slimefun's util package.
What do the others think?

@J3fftw1
Copy link
Member

J3fftw1 commented Jun 14, 2022

I really find Preconditions.checkNotNull better semantic wise but it's a shame that it throws an NPE...

I was really hoping we could avoid writing our own util for it, but it really seems like Preconditions doesn't cover our use cases too well...

Perhaps a Validate class should be added to dough-common then... or Slimefun's util package. What do the others think?

I would say push this to Dough so plugins that use Dough only and not Slimefun can make use of it aswell.

@variananora variananora added the 🧹 Chores Refactoring / Cleanup. label Jun 18, 2022
@ybw0014
Copy link
Contributor Author

ybw0014 commented Jun 29, 2022

I'll open a new pr when Slimefun/dough#184 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧹 Chores Refactoring / Cleanup.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace Validate checks from commons-lang with Preconditions checks from Guava
5 participants