openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (OPENJPA-2205) Performance - Method invokes inefficient Number constructor; use static valueOf instead
Date Fri, 01 Jun 2012 18:19:22 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-2205?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13287574#comment-13287574
] 

James Carman commented on OPENJPA-2205:
---------------------------------------

Details about the FindBugs error:

Using new Integer(int) is guaranteed to always result in a new object whereas Integer.valueOf(int)
allows caching of values to be done by the compiler, class library, or JVM. Using of cached
values avoids object allocation and the code will be faster.

Values between -128 and 127 are guaranteed to have corresponding cached instances and using
valueOf is approximately 3.5 times faster than using constructor. For values outside the constant
range the performance of both styles is the same.

Unless the class must be compatible with JVMs predating Java 1.5, use either autoboxing or
the valueOf() method when creating instances of Long, Integer, Short, Character, and Byte.

                
> Performance - Method invokes inefficient Number constructor; use static valueOf instead
> ---------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2205
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2205
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: Enhance
>    Affects Versions: 2.2.0
>            Reporter: James Carman
>
> We use Sonar and all of our enhanced classes cause this "critical" bug to come up.  I
believe it's found via FindBugs.
> The pcCopyKeyFieldsFromObjectId() method appears to be the offender here.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message