apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
8.27k stars 2.09k forks source link

Error prone BoxedPrimitiveConstructor warning in src\core\org\apache\jmeter\report\processor\Top5ErrorsSummaryData.java file #4208

Closed asfimport closed 7 years ago

asfimport commented 7 years ago

Antonio Gomes Rodrigues (Bug 60535): Hi,

I have run http://errorprone.info tool into JMeter code and it detect some warning

[javac] C:\Util\0_perso\JMeterSVN\jmeter\src\core\org\apache\jmeter\report\processor\Top5ErrorsSummaryData.java:32: warning: [BoxedPrimitiveConstructor] valueOf or autoboxing provides better time and space performance
[javac]     private static final Long ONE = new Long(1);
[javac]                                     ^
[javac]     (see http://errorprone.info/bugpattern/BoxedPrimitiveConstructor)
[javac]   Did you mean 'private static final Long ONE = (long) 1;'?

If we check http://errorprone.info/bugpattern/BoxedPrimitiveConstructor, we can read

Constructors of primitive wrapper objects (e.g. new Boolean(true) will be deprecated in Java 9. The valueOf factory methods (e.g. Boolean.valueOf(true)) should always be preferred. Those methods are called implicitly by autoboxing, which is often more convenient than an explicit call. Integer x = Integer.valueOf(23); and Integer x = 23; are equivalent.

The explicit constructors always return a fresh instance, resulting in unnecessary allocations. The valueOf methods return cached instances for frequently requested values, offering significantly better space and time performance.

Relying on the unique reference identity of the instances returned by the explicit constructors is extremely bad practice. Primitives should always be treated as identity-less value types, even in their boxed representations.

Antonio

OS: All

asfimport commented 7 years ago

Antonio Gomes Rodrigues (migrated from Bugzilla): PR https://github.com/apache/jmeter/pull/244 commited

asfimport commented 7 years ago

Antonio Gomes Rodrigues (migrated from Bugzilla): Fix commited