GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] UseObjectForClearerAPI Only For Public by Vampire · Pull Request #1752 · pmd/pmd

Conversation

@Vampire

@Vampire Vampire commented Apr 2, 2019 •
edited by adangel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The description and implementation of the rule suggest that is should only apply
to public methods, but it is effective against all methods as for the existence
of the @Public attribute is tested instead of the value, so the condition is
always true.

With this fix, only public methods are considered like intended.

Fixes #1760

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ghost

ghost commented Apr 2, 2019 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
1 Message
📖 This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 20 violations, 2 errors and 0 configuration errors.
Full report
✅ This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 12 violations, 2 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jsotuyod

jsotuyod commented Apr 3, 2019

Copy link
Copy Markdown
Member

@Vampire thanks for the PR! You are absolutely right about this.

Would you care to include a unit test to make sure the issue is never reintroduced in the future? Just adding a new <test-code> under UseObjectForClearerAPI with a private method expecting 0 violations should be enough.

Thanks in advance!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jsotuyod jsotuyod added the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Apr 3, 2019
@Vampire

Vampire commented Apr 3, 2019

Copy link
Copy Markdown
Contributor Author

Sure, I'll have a look. One question though, is it intended that String and String[] are treated as the same?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Vampire

Vampire commented Apr 3, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

And if not, is it an error of the rule that is uses @Image, or is it an error of the AST, that the @Image for String[] is String?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Vampire
Fix UseObjectForClearerAPI rule that checked non-public methods
06625b2
@oowekyala

oowekyala commented Apr 3, 2019

Copy link
Copy Markdown
Member

@Vampire The ReferenceType node has an attribute @ArrayDepth to get the number of dimensions of the array.

Quite honestly I don't see the point of this method and why it only counts strings. There's already a rule TooManyParameters or ParameterCount idk whose proposed correction is to use an object. Maybe that one should be enriched with an option to ignore private methods instead, and this rule dropped. Is there something I'm not seeing about why string parameters in particular are bad?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Vampire

Vampire commented Apr 3, 2019

Copy link
Copy Markdown
Contributor Author

I don't know, I just wondered about why it complains about a private method when the description said it only checks public methods.
I guess this is also the reason it was in the "controversial" category before it was moved to the "design" category.

So independent of whether this gets deprecated and replaced by some other rule, when I'm at fixing this, should I also check the array depth as the description says it is only about Strings?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Vampire
Fix UseObjectForClearerAPI rule that treated String and String[] the …
f3c0d39
…same
@Vampire
Vampire force-pushed the UseObjectForClearerAPI-only-for-public branch from f710edb to f3c0d39 Compare April 3, 2019 10:00
@Vampire

Vampire commented Apr 3, 2019

Copy link
Copy Markdown
Contributor Author

I pushed a version now that has tests and also checks for array.

oowekyala reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel self-assigned this Apr 5, 2019
@adangel

adangel commented Apr 5, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Let me chime in:

  • The intention of the rule is clearly to only check for public methods. So, this bug is fixed by this PR. 👍
  • The rule is very, very narrowed in its use case: only strings, it starts to complain at a fixed string parameter number of 3, so not configurable. I'd say, we should deprecate this rule and remove it with PMD 7. I'll put it onto the backlog in the wiki for now. -> https://github.com/pmd/pmd/wiki/PMD-7.0.0
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added a:false-positive PMD flags a piece of code that is not problematic and removed is:WIP For PRs that are not fully ready, or issues that are actively being tackled labels Apr 5, 2019
@adangel adangel added this to the 6.14.0 milestone Apr 5, 2019
@adangel adangel changed the title [java] Useobjectforclearerapi Only For Public [java] UseObjectForClearerAPI Only For Public Apr 5, 2019
@adangel adangel mentioned this pull request Apr 5, 2019
[java] UseObjectForClearerAPI flags private methods #1760
Closed
adangel
adangel approved these changes Apr 5, 2019
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks good, thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@adangel
adangel merged commit f3c0d39 into pmd:master Apr 5, 2019
adangel added a commit that referenced this pull request Apr 5, 2019
@adangel
Update release notes, fixes #1760, refs #1752
aa10258
@Vampire
Vampire deleted the UseObjectForClearerAPI-only-for-public branch April 5, 2019 21:22
@Vampire Vampire mentioned this pull request Apr 8, 2019
Issue #6490: Add MultipleVariableDeclarations check to Sun style config checkstyle/checkstyle#6567
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

a:false-positive PMD flags a piece of code that is not problematic

Projects

None yet

Milestone

6.14.0

Development

Successfully merging this pull request may close these issues.

[java] UseObjectForClearerAPI flags private methods

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Vampire @jsotuyod @oowekyala @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.