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

new Check: EmptyPublicCtorInFinalClassCheck #186

Closed
romani opened this Issue May 10, 2014 · 1 comment

Comments

Projects
None yet
5 participants
@romani
Member

romani commented May 10, 2014

following code is happen :

class MyClass {
 MyClass() {
   super();
 }
}

nobody extend this class, this class does not extend anything - its c-tor is completely useless, especially "super()";

Checkstyle idea - EmptyPublicCtorInFinalClass,

base on investigation why empty ctor could be necessary - http://stackoverflow.com/questions/3507281/java-inheritance-problem-have-to-create-empty-constructor-in-father-class,

we can not completely cover code case that described above, as Checkstyle does not have information about other classes (nobody can predict who can extend from MyClass).

What we can be sure is final class can not be extended - so we could catch that cases.
Nuances:

  • we can check class only if it final and do not "extend" anything.
  • private c-tor is OK in utility classes.
  • ignoreSuperCtorCall - Additionally check for "super();" in class's non default c-tor and this class does not extend anything.
  • even class is not final, but do not extend anything , call of "super();" is useless and should be caught by this Check.

@daniilyar daniilyar added moderate and removed enhancement labels Aug 15, 2014

@daniilyar daniilyar assigned Alexey2701 and alex-zuy and unassigned Alexey2701 Oct 14, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Oct 29, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Oct 29, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Oct 29, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Oct 29, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Oct 29, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Oct 29, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Nov 11, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Nov 18, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Nov 18, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Nov 28, 2014

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Nov 29, 2014

Member

just for future reference: http://stackoverflow.com/a/6318640

Member

romani commented Nov 29, 2014

just for future reference: http://stackoverflow.com/a/6318640

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Nov 29, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Dec 24, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Dec 28, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Dec 28, 2014

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Jan 2, 2015

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Jan 2, 2015

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Jan 2, 2015

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Jan 29, 2015

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Jan 29, 2015

alex-zuy added a commit to alex-zuy/sevntu.checkstyle that referenced this issue Feb 1, 2015

@romani romani closed this in 16e829e Feb 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment