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

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

Open
dgroup opened this issue Jun 1, 2019 · 5 comments
Open

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

dgroup opened this issue Jun 1, 2019 · 5 comments

Comments

@dgroup
Copy link
Contributor

dgroup commented Jun 1, 2019

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
Copy link
Collaborator

0crat commented Jun 1, 2019

@krzyk/z please, pay attention to this issue

@0crat
Copy link
Collaborator

0crat commented Jun 1, 2019

@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
Copy link
Contributor

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

@yegor256
Copy link
Owner

@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
Copy link

PeJetuz commented Jul 9, 2024

@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;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants