description of the Rule answering to the question “why?” : what’s the impact to keep this code as it is ?
This bug was found in a production app, resulting in it using way more memory than intended. The developers were trying to implement something like a Multimap, but didn’t realize that the code was calling the ArrayList constructor that takes an argument for the initial size. They intended to have empty lists.
I have already successfully implemented this rule, and am ready to submit the code.
snippet of Noncompliant Code
// Create a Multimap of account ID -> List of attributes. Make sure that there's an entry for every account. Arrays.asList(1, 2, 54000).stream().collect(Collectors.toMap(Function.identity(), ArrayList::new));
- snippet of Compilant Code (fixing the above noncompliant code)
Arrays.asList(1, 2, 54000).stream().collect(Collectors.toMap(Function.identity(), id -> new ArrayList<>()));
external references and/or language specifications
type : Bug, Vulnerability, Code Smell ?