#1214 Lower confidence for NP_LOAD_OF_KNOWN_NULL_VALUE on Arrays.asList() calls

3.x
closed-rejected
None
5
2017-10-22
2013-10-31
No

In the code below FB reports NP_LOAD_OF_KNOWN_NULL_VALUE warning for using "arg1" value in the varargs argument passed to Arrays.asList() method.

Rank: Of Concern (16), confidence: Normal

public class TestNullParameter {
public static void main(String[] args) {
String arg1 = args[0];
String arg2 = args[1];
String arg3 = args[2];

    if (arg1 != null) {
        System.out.println(arg1);
        return;
    }
    List<?> list = Arrays.asList(arg1, arg2, arg3);
    throw new IllegalArgumentException("Bad args: " + list.toString());
}

}

The code like above is automatically generated by XText and so shows up in multiple places in absolutely valid (but generated) code.

I think is the loaded value is not a single one, but part of vararguments, we should lower the confidence.

Discussion

  • William Pugh

    William Pugh - 2013-10-31
    • status: open --> open-postponed
    • Group: 2.0.3 --> 2.1.0
     
  • William Pugh

    William Pugh - 2013-10-31

    I'm not sure why this case is any lower priority than other cases of loading a null value. The Arrays.asList statement is equivalent to

    List<?> list = Arrays.asList(null, arg2, arg3);
    

    I don't think putting loading a known null value and putting it into a varargs is a particularly good indicator. Perhaps the fact that it happens at a doomed location is a reason to lower the priority, or use a new bug pattern.

    Is there an easy way to determine that the code was generated by XText?

    More investigation needed. Perhaps 2.1.0.

     
  • Andrey Loskutov

    Andrey Loskutov - 2014-06-19
    • Group: 3.0.0 --> 3.0.1
     
  • Andrey Loskutov

    Andrey Loskutov - 2017-10-22
    • Status: open-postponed --> closed-rejected
     

Log in to post a comment.