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 — Add CloneMethodReturnTypeMustMatchClassName rule by DTecheira · Pull Request #61 · pmd/pmd

Conversation

@DTecheira

@DTecheira DTecheira commented Jul 31, 2015

Copy link
Copy Markdown
Contributor

If we have a class that implements cloneable the return type of our clone method should match with the class name instead of returning Object.

This makes sense since clone is expected to return an exact copy of the object; and since the return type is not part of the signature, it's still a valid override.

public class Foo implements Cloneable {
    @Override
    public Object clone() { // Should be Foo
    }
}

This is not required by the contract of Object.clone (even the Javadoc says so), but is a sane default; and exceptions may suppress this rule were needed.

Sorry, something went wrong.

Uh oh!

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

All reactions
@DTecheira
Add CloneMethodReturnTypeMustMatchClassName rule
445bd2d
Test Plan: mvn test

Reviewers: jmsotuyo

Reviewed By: jmsotuyo

Differential Revision: http://ph.monits.com/D12031
@jsotuyod

jsotuyod commented Aug 11, 2015

Copy link
Copy Markdown
Member

To bare in mind, doing this is only valid (an recommended) in Java 5+.

All reactions

Sorry, something went wrong.

Uh oh!

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

@adangel

adangel commented Aug 18, 2015

Copy link
Copy Markdown
Member

You are right, thanks for the hint.
It is actually possible to make this rule java 5+ only: by adding the attribute minimumLanguageVersion="1.5" in the ruleset.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jsotuyod

jsotuyod commented Aug 18, 2015

Copy link
Copy Markdown
Member

Awesome, didn't know! Do you want @DTecheira to change it or will you do it yourself when you merge?

All reactions

Sorry, something went wrong.

Uh oh!

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

@adangel

adangel commented Aug 18, 2015

Copy link
Copy Markdown
Member

I can do it, when I merge it. However, it will take probably 2 more weeks before I find time to work on this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jsotuyod

jsotuyod commented Aug 18, 2015

Copy link
Copy Markdown
Member

If there is anyway in which we can help just let us know! At @Monits we make heavy use of PMD, and just as we did these few rules @DTecheira submitted, we are planning on working on a crash and a couple FP on some existing rules on the next few days.

We are more than open to invest development time on other things too if that will help you / PMD. It's our way of giving back to such an amazing tool. Feel free to contact me to coordinate efforts.

All reactions

Sorry, something went wrong.

Uh oh!

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

@DTecheira

DTecheira commented Aug 19, 2015

Copy link
Copy Markdown
Contributor Author

Sorry for the delay, I will add this, today.

All reactions

Sorry, something went wrong.

Uh oh!

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

@DTecheira
Add language version attribute
d9d02ed
Test Plan: mvn test

Reviewers: jmsotuyo

Reviewed By: jmsotuyo

Subscribers: jmsotuyo

Differential Revision: http://ph.monits.com/D12205
@DTecheira

DTecheira commented Aug 19, 2015

Copy link
Copy Markdown
Contributor Author

Done

All reactions

Sorry, something went wrong.

Uh oh!

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

@adangel
adangel merged commit d9d02ed into pmd:master Aug 31, 2015
@adangel

adangel commented Aug 31, 2015

Copy link
Copy Markdown
Member

Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

@jsotuyod
jsotuyod deleted the addCloneMethodReturnTypeMustMatchClassNameRule branch September 9, 2015 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

@DTecheira @jsotuyod @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.