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

[java] AccessorClassGeneration false positive for private constructors #755

Closed
dotdoom opened this issue Nov 24, 2017 · 3 comments
Closed
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@dotdoom
Copy link

dotdoom commented Nov 24, 2017

Rule Set:
Design: AccessorClassGeneration

Description:
When there are both private and public constructors in inner class, with the same number of arguments but different types, PMD assumes that private is called from the outer class even public is actually called.

Code Sample demonstrating the issue:

public class Outer
{
  public static class Inner {
    private Inner(int x) { }
    public Inner(Object x) { }
  }
  
  public static void main(String[] args)
  {
    // PMD.AccessorClassGeneration
    // Avoid instantiation through private constructors from outside of the constructors class.
    new Inner(null); // complains as if Inner(int) is was called
  }
}

Running PMD through: [Gradle]

@dotdoom
Copy link
Author

dotdoom commented Nov 24, 2017

@jsotuyod jsotuyod added the a:false-positive PMD flags a piece of code that is not problematic label Nov 25, 2017
@jsotuyod
Copy link
Member

jsotuyod commented Nov 25, 2017

@dotdoom thanks for the feedback! You are absolutely right on this one. That TODO is not exactly related to your issue, but refers to a time where type resolution support was non-existing.

You are absolutely right about this one. 6.0.0 is already too close to release, but this should definitely make it into 6.1.0

@jsotuyod jsotuyod added this to the 6.1.0 milestone Nov 25, 2017
@adangel adangel modified the milestones: 6.1.0, 6.2.0 Feb 25, 2018
@adangel adangel assigned ghost Mar 14, 2018
@adangel adangel modified the milestones: 6.2.0, 6.3.0 Mar 26, 2018
@adangel adangel modified the milestones: 6.3.0, 6.4.0 Apr 28, 2018
@jsotuyod jsotuyod modified the milestones: 6.4.0, 6.5.0 May 29, 2018
@jsotuyod jsotuyod removed this from the 6.5.0 milestone Jun 24, 2018
@oowekyala oowekyala added this to the 7.0.0 milestone Dec 15, 2020
oowekyala added a commit that referenced this issue Dec 15, 2020
@oowekyala
Copy link
Member

oowekyala commented Dec 15, 2020

Was fixed in #2899 for PMD 7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

No branches or pull requests

4 participants