OpenJPA
  1. OpenJPA
  2. OPENJPA-2205

Performance - Method invokes inefficient Number constructor; use static valueOf instead

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.2.0
    • Fix Version/s: None
    • Component/s: Enhance
    • Labels:
      None

      Description

      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.

        Activity

        James Carman created issue -
        James Carman made changes -
        Field Original Value New Value
        Description We use Sonar and all of our enhanced classes all cause this "critical" bug to come up. I believe it's found via FindBugs.

        The pcCopyKeyFieldsFromObjectId() method appears to be the offender here.
        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.
        Hide
        James Carman added a comment -

        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.

        Show
        James Carman added a comment - 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.
        Hide
        Martin Baumgartner added a comment -

        As far as i could see, the affected code becomes generated in PCEnhancer:addCopyKeyFieldsFromObjectIdMethod, but I'm not familiar with Serp.

        Show
        Martin Baumgartner added a comment - As far as i could see, the affected code becomes generated in PCEnhancer:addCopyKeyFieldsFromObjectIdMethod, but I'm not familiar with Serp.
        Rick Curtis made changes -
        Issue Type Bug [ 1 ] Improvement [ 4 ]
        Priority Major [ 3 ] Minor [ 4 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            James Carman
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development