yegor256 / qulice

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

new ListOf<>(array) violates PMD ArrayIsStoredDirectly #1053

Open dgroup opened 5 years ago

dgroup commented 5 years ago

On qulice v0.18.19

public App(final String... args) {
  this.args = new ListOf<>(args);
}

gives PMD The user-supplied array 'args' is stored directly. (ArrayIsStoredDirectly). What's wrong with it?

0crat commented 5 years ago

@krzyk/z please, pay attention to this issue

0crat commented 5 years ago

@dgroup/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!

pnatashap commented 6 months ago

@yegor256 may be really it is better to disable this rule? https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#arrayisstoreddirectly

yegor256 commented 4 months ago

@pnatashap well, it's a good rule, I believe. Maybe, we should take their rule, copy it to our code base, and then modify it so that it only alarms when this happens:

this.args = args;

But doesn't alarm if:

this.args = any_other_method_call_or_constructor(args);
PeJetuz commented 2 months ago

@pnatashap @yegor256 If I get you right. I tried to reproduce this (versions 0.18.19 and 0.23.0) but I only got errors in the following code:

public final class Temp2 {
    private final String[] list;

    public Temp2(final String... arg) {
        this.list = arg;
    }
}

The following code did not generate errors:

public final class Temp {
    private final List<String> list;

    public Temp(final String... arg) {
        this.list = new ListOf<>(arg);
    }
}

public final class Temp4 {
    private final String[] list;

    public Temp4(final String... arg) {
        this.list = Temp4.conv(arg);
    }

    private static String[] conv(final String... arg) {
        return arg;
    }
}