You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alexander van de Rovaart (Jira)" <ji...@apache.org> on 2021/02/04 11:01:00 UTC
[jira] [Created] (LANG-1643) Initialize Arraylist in EqualsBuilder
with size 1
Alexander van de Rovaart created LANG-1643:
----------------------------------------------
Summary: Initialize Arraylist in EqualsBuilder with size 1
Key: LANG-1643
URL: https://issues.apache.org/jira/browse/LANG-1643
Project: Commons Lang
Issue Type: Improvement
Components: lang.builder.*
Environment: {code}
:~$ java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
:~$ uname -a
Linux ubuntu 5.8.0-41-generic #46~20.04.1-Ubuntu SMP Mon Jan 18 17:52:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Apache commons lang3 version 3.11
{code}
Reporter: Alexander van de Rovaart
Attachments: image-2021-02-04-11-45-47-437.png
In the constructor the EqualsBuilder the variabele {{bypassReflectionClasses}} is initialized with an {{new ArrayList()}} and immidiately after that a vaue is added. This will result in an ArrayList.grow() because the contructor of ArrayList will initialize is with a zero length array. See attached screenshot for a stacktrace from a flight recording.
My suggestion would be to initialize the arraylist with a length of 1 or the default of 10 that is used in java.util.ArrayList when it is initially grown on the first add.
So the code sample of the constructor would be:
{code:java}
public EqualsBuilder() {
// set up default classes to bypass reflection for
bypassReflectionClasses = new ArrayList<>(1);
bypassReflectionClasses.add(String.class); //hashCode field being lazy but not transient
}
{code}
!image-2021-02-04-11-45-47-437.png!
--
This message was sent by Atlassian Jira
(v8.3.4#803005)