Bug 58547

Summary: Avoid new Integer and new Long instances when doing conversions
Product: Tomcat 8 Reporter: Anthony Whitford <anthony>
Component: UtilAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: trivial    
Priority: P2    
Version: 8.0.x-trunk   
Target Milestone: ----   
Hardware: Macintosh   
OS: Mac OS X 10.1   
Attachments: Replaced new Integer/Long with valueOf calls

Description Anthony Whitford 2015-10-25 23:22:01 UTC
Created attachment 33219 [details]
Replaced new Integer/Long with valueOf calls

Discovered cases where an inefficient Number constructor is being called instead of the static valueOf.

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.

See http://findbugs.sourceforge.net/bugDescriptions.html#DM_NUMBER_CTOR
Comment 1 Violeta Georgieva 2015-10-27 11:01:30 UTC
Hi,

Thanks for the report and the patch.
I applied the same fix on other places in the code also.
The fix is available in trunk, 8.0.x (for 8.0.29 onwards) and 7.0.x (for 7.0.66
onwards)

Regards,
Violeta