Skip to content

[java] New rule ReturnEmptyCollectionRatherThanNull#3382

Merged
adangel merged 4 commits into
pmd:masterfrom
jsotuyod:update-null-collections
Jul 16, 2021
Merged

[java] New rule ReturnEmptyCollectionRatherThanNull#3382
adangel merged 4 commits into
pmd:masterfrom
jsotuyod:update-null-collections

Conversation

@jsotuyod

@jsotuyod jsotuyod commented Jul 5, 2021

Copy link
Copy Markdown
Member

Describe the PR

Create a new ReturnEmptyCollectionRatherThanNull to supersede the old ReturnEmptyArrayRatherThanNull.

The same principle applies not only to arrays, but to all collections (java.util.Collections even providing easy no-alloc methods to return empty maps, lists and sets).

I doubted if this should more generally look at any java.lang.Iterable, but I felt that was stretching it too much (and it would not on it's own consider maps).

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

jsotuyod added 3 commits July 5, 2021 18:07
 - Deprecate the old ReturnEmptyArrayRatherThanNull, and supersede it
with a new rule that contmplates not only arrays, but all members of the
Java Collection Framework (Maps, Lists, Sets and even the legacy Vector
and Hashtable).
@ghost

ghost commented Jul 5, 2021

Copy link
Copy Markdown
1 Message
📖 This changeset changes 0 violations,
introduces 234 new violations, 0 new errors and 0 new configuration errors,
removes 147 violations, 0 errors and 0 configuration errors.
Full report
This changeset changes 0 violations,
introduces 234 new violations, 0 new errors and 0 new configuration errors,
removes 147 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

@jsotuyod jsotuyod added this to the 6.37.0 milestone Jul 6, 2021
@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Jul 10, 2021
Comment thread pmd-java/src/main/resources/category/java/errorprone.xml
Comment thread pmd-java/src/main/resources/category/java/errorprone.xml
Comment on lines +30 to +32
The following Java rules are deprecated and removed from the quickstart ruleset,
as the new rule {% rule java/errorprone.xml/ReturnEmptyCollectionRatherThanNull %} supersedes it:
* {% rule java/errorprone.xml/ReturnEmptyArrayRatherThanNull %}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
The following Java rules are deprecated and removed from the quickstart ruleset,
as the new rule {% rule java/errorprone.xml/ReturnEmptyCollectionRatherThanNull %} supersedes it:
* {% rule java/errorprone.xml/ReturnEmptyArrayRatherThanNull %}
The rule {% rule java/errorprone.xml/ReturnEmptyArrayRatherThanNull %} is deprecated and removed from the quickstart ruleset,
as the new rule {% rule java/errorprone.xml/ReturnEmptyCollectionRatherThanNull %} supersedes it.

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!
I'll do the little fixups when merging

adangel added a commit that referenced this pull request Jul 16, 2021
adangel added a commit that referenced this pull request Jul 16, 2021
[java] New rule ReturnEmptyCollectionRatherThanNull #3382
@adangel adangel merged commit 9b9ce19 into pmd:master Jul 16, 2021
@jsotuyod jsotuyod deleted the update-null-collections branch July 16, 2021 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants