Content of collection are updated, but never queried.

已回答

I have that code:

public void foo(){
ArrayList<Integer> arr=new ArrayList<>();
arr.add(0,10);
}

But intellij keep telling me that warning: "Content of collection are updated, but never queried"
The warning mark is on the "arr" word in the first line (in declaration).
but if I write that code:

public void foo(){
ArrayList<Integer> arr=new ArrayList<>();
}

there is no warning.
I have seen some topics that saying to suppress that warning, but how can I fix it without suppressing..
why is that occur?
Thanks.

1

Full description of the inspection:

Reports collection fields or variables whose contents are either queried and not updated, or updated and not queried. Such mismatched queries and updates are pointless, and may indicate either dead code or a typographical error.
Use the tables below to specify which methods are update and/or query methods. The names are matched with the beginning of the method name. Query methods which return their result are automatically detected, only query methods which return their result in an argument (e.g. write to OutputStream) need to be specified.

That is exactly what happens. You add an element to a collection, but don't do anything else with it (like print the value of this element or return it from the method, etc). This way this code is dead in its current state. Either complete the code or remove it.

4
Avatar
Permanently deleted user

Thank you very much.!!! You really helped me.

0
Avatar
Permanently deleted user

<graveDigExcuse>I see this is an old topic however since I found this via Google, I assume others will find it as well.</graveDigExcuse>

This inspection has always been useful to me. However, now that I'm working in Angular 5 (and its predecessors may be effected as well) I get this warning when I build an array in a component and iterate in an `ngFor` inside an HTML template. From what Serge mentioned above, "You add an element to a collection, but don't do anything else with it (like print the value of this element or return it from the method, etc)," the inspection seems to be warning in error - not detecting the usage.

0

Hello,

Please report new issue on YouTrack: http://youtrack.jetbrains.com/issues/WEB

0

I got this warning in library which is Nuget and it is accessed externally. Can I turn of such analyzer only in this project?

0

You can suppress warnings per project, per file or per line of code, see https://www.jetbrains.com/help/idea/disabling-and-enabling-inspections.html#suppress-in-editor.

But it looks like you are using Rider? In this case the correct support page would be https://rider-support.jetbrains.com/hc/en-us.

0

Quick Additional Edge Case Info on this:

If a given value is all in a string interpolation, this feature will incorrectly point out the no-query error.  I have just seen this in TypeScript situation. Probably rare but might confuse some coders.

```
let edgeLabels: string[]

if (upperLevel) {
    edgeLabels = outEs.filter(
        (e: any) => {
            return e.outV.id === upperVid
        }
    ).map((e: any) => {
        return e.label as string
    })
} else {
    edgeLabels = []
}

doing.info(`${edgeLabels}`)

0

It looks like https://youtrack.jetbrains.com/issue/WEB-63572. Feel free to follow it to be notified about updates.

0

请先登录再写评论。