Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
None
-
:~$ 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
:~$ 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
Description
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 screenshots 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 calls to ArrayList.grow and ArrayList.newCapacity and Arrays.copyOf won't be called when calling the add function after construction.
So the code sample of the constructor would be:
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 }
Attachments
Attachments
Issue Links
- links to