You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2011/05/09 11:41:26 UTC

DO NOT REPLY [Bug 51175] New: [Patch] Proposal: Avoid Autoboxing

https://issues.apache.org/bugzilla/show_bug.cgi?id=51175

             Bug #: 51175
           Summary: [Patch] Proposal: Avoid Autoboxing
           Product: POI
           Version: unspecified
          Platform: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XWPF
        AssignedTo: dev@poi.apache.org
        ReportedBy: stefan.stern@mind8.com
    Classification: Unclassified


Created attachment 26976
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=26976
Converts all occurrences of autoboxing / auto-unboxing into explicit
conversions.

As Autoboxing may cause some trouble during runtime, I propose to avoid it and
use explicit conversions where needed. An example line of code for
misunderstandings is this:

[code]
Integer index = 5;
List<ExampleObjects> list = getExampleList();
list.remove(index);
[/code]

One might expect to have element at index 5 removed from the list. But the API
will call the method with signature List#remove(Object), so nothing happens. 

If reading the code in terms of another issue, one can easily miss the
difference and wonder why on earth the element at index 5 was not removed. 

Therefore, I added explicit conversion whereever I found autoboxing takes place
in the XPWF classes. This includes a minor API change for two methods in
XWPFDocument, where "Integer" was used as return type, while "int" is
sufficient and fits better into the rest of the get-index-methods of XWPF.

Of course, this is a matter of coding style. So this just a proposal.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 51175] [Patch] Proposal: Avoid Autoboxing

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51175

Nick Burch <ni...@alfresco.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|                            |All

--- Comment #1 from Nick Burch <ni...@alfresco.com> 2011-05-09 10:49:38 UTC ---
I agree we should probably avoid returning Integer or Boolean from methods
wherever possible. Possibly within the code too, but List<Integer>
interchanging with int for example is one case where we probably don't want too
much explicit code cluttering up.

I'll try to review the patch shortly.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 51175] [Patch] Proposal: Avoid Autoboxing

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51175

--- Comment #2 from Stefan Stern <st...@mind8.com> 2011-05-09 11:45:04 UTC ---
Whether to use or not to use Autoboxing, that is one of those issues that turn
out to become religious conflicts. After I stumbled over the List API, I
decided to avoid them. But yes, it tends to inflate the code. 

Just keep in mind, how easily the following lines can be misunderstood:

[code]
List<Integer> list = new ArrayList<Integer>();

list.add(0);
list.add(1); 
list.add(2);
list.add(3);
list.add(2,4);
list.add(7);

list.remove(0);
list.remove(3);
list.remove(new Integer(3));
list.remove(7);
[/code]

Just my 2 cents. ;)

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 51175] [Patch] Proposal: Avoid Autoboxing

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51175

Nick Burch <ni...@alfresco.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #3 from Nick Burch <ni...@alfresco.com> 2011-05-13 12:22:52 UTC ---
Applied (with a few tweaks) in r1102691, thanks!

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org