Bug 47962

Summary: Fix string literal bugs and inefficient object creation
Product: POI Reporter: David Horwitz <dhorwitz>
Component: POI OverallAssignee: POI Developers List <dev>
Severity: normal CC: dhorwitz
Priority: P2    
Version: 3.5-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Fix string leteral first and inneficient obejct creation
Improved patch - please disregard earlier

Description David Horwitz 2009-10-08 02:22:26 UTC
Created attachment 24361 [details]
Fix string leteral first and inneficient obejct creation

The attached patch fixes 600+ occurrences of 2 common bug patterns identified
by Findbugs and other automated code checkers they are:

1) String literal first bugs (foo.equals("") rather than "".equals(foo))
2) Inefficient object creation (String, Boolean, Integer, Long) - e.g. new
Long(1) rather than Long.valueOf(1)
Comment 1 David Horwitz 2009-10-08 02:30:12 UTC
Created attachment 24362 [details]
Improved patch - please disregard earlier

PLease use second patch the first contains 2 errors
Comment 2 Josh Micich 2009-10-08 16:05:31 UTC
Thanks for the patch - some good clean up work.

Applied in svn r823348 with mods

Not all occurrences of 'foo.equals("bar")' were changed to '"bar".equals(foo)'.  Presumably this change is intended to reduce the likelihood of a NullPointerException.  In many cases however, it was clear that 'foo' could not be null, and the code was left as-is for readability.

Regarding the box constructor vs valueOf() method changes - I'm pretty sure there were no places where POI needs distinct instances, so most of these were OK.  However, a few changes were not applied for these reasons:
  - caching of box instances generally applies to small integral values near zero.
  - Double.valueOf(double) does not utilize a DoubleCache or similar.
  - Boolean.FALSE is better than Boolean.valueOf(false).

If you are keen to fix other compiler warnings that would be very much appreciated.  Please try to keep the patches smaller, to make them easier to QA.