jmeter-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 60535] New: Error prone BoxedPrimitiveConstructor warning in src\core\org\apache\jmeter\report\processor\Top5ErrorsSummaryData.java file
Date Fri, 30 Dec 2016 12:10:16 GMT
https://bz.apache.org/bugzilla/show_bug.cgi?id=60535

            Bug ID: 60535
           Summary: Error prone BoxedPrimitiveConstructor warning in
                    src\core\org\apache\jmeter\report\processor\Top5Errors
                    SummaryData.java file
           Product: JMeter
           Version: 3.1
          Hardware: PC
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Main
          Assignee: issues@jmeter.apache.org
          Reporter: ra0077@gmail.com
  Target Milestone: ---

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

-- 
You are receiving this mail because:
You are the assignee for the bug.
Mime
View raw message