yegor256 / qulice

Quality Police for Java projects: aggregator of Checkstyle and PMD
https://www.qulice.com
Other
299 stars 110 forks source link

Constructors should be really code free #755

Open krzyk opened 8 years ago

krzyk commented 8 years ago

Our current rules allow constructors that assign fields using static methods, this should be forbidden, only field assignment from constructor parameters or new classes creation should be allowed (and calling other constructors).

Wrong:

public Foo(final int param) {
    this.param = param;
    this.bar = Foo.createBar();
}

private static final int createBar() {...}

Correct:

public Foo(final int param, final int bar) {
    this.param = param;
    this.bar = bar;
}

Also correct:

public Foo(final int param, final int bar) {
    this.param = param;
    this.bar = new SomeClass();
}
krzyk commented 8 years ago

@davvd valid bug

davvd commented 8 years ago

@davvd valid bug

@krzyk tag "bug" added

davvd commented 8 years ago

@krzyk thank you for reporting this, I added 30 mins to your acc, transaction 80640518

krzyk commented 8 years ago

@davvd please add also a bonus for "NonStaticMethodCheck complains about overriden methods" #595 @yegor256 you mean such random mention or something more specific?

yegor256 commented 8 years ago

@davvd pls add extra 30 mins to @krzyk

davvd commented 8 years ago

@davvd pls add extra 30 mins to @krzyk

@yegor256 I've sent 30 mins extra to @krzyk in transaction ID "80811950"

krzyk commented 8 years ago

@davvd this is postponed

davvd commented 8 years ago

@davvd this is postponed

@krzyk thanks, I added "postponed" label

davvd commented 8 years ago

@davvd this is postponed

@krzyk I will assign somebody else to this issue