Bug 63805

Summary: RFE: Leverage language features introduced in Java 8, remove use of deprecated methods
Product: POI Reporter: Axel Howind <axel>
Component: POI OverallAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: P2    
Version: 4.0.x-dev   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: BigDecimal: use enum args instead of integers (deprecated in Java 9)
use zero size arg to toArray(), use Collection.addAll()
clean up IntList code
in some places, Objects.equals could be used instead
Strings: Replace StringBuffer with StringBuilder, use indexOf(char) instead of indexOf(String) where possible

Description Axel Howind 2019-10-04 16:19:30 UTC
While I still have time working on POI, I'd like to contribute patches to update the codebase to take advantage of features introduced in Java 8 and replace parts of the code that use deprecated methods.

I would do so in a way that does not change semantics or behaviour (other than hopefully positive impact on performance). Examples I have seen in the code are:

- use of StringBuffer instead of StringBuilder
- Map lookup and get/put in two steps which can be done in a single operation since in the meantime computeIfAbsent() and other methods were introduced
- toArray() with an argument of T[0] (I know it's faster than pre-allocating an array with the correct size, but now we can pass a method reference to the array constructor instead which is even faster and puts less stress on the GC)
- places where single operation collection creation could be used, i.e. List.of() for creating an immutable list

and many more.

If I get a positive feedback, I'll create patches and collect them here (or pull requests if github mirroring works again soon).
Comment 1 Dominik Stadler 2019-10-06 18:00:48 UTC
Patches welcome! Would be good if you can split them for each type of change so we can apply them in smaller steps and verify if things still work.
Comment 2 Axel Howind 2019-10-07 12:50:38 UTC
Created attachment 36809 [details]
BigDecimal: use enum args instead of integers (deprecated in Java 9)
Comment 3 Axel Howind 2019-10-07 12:53:54 UTC
Created attachment 36810 [details]
use zero size arg to toArray(), use Collection.addAll()
Comment 4 Axel Howind 2019-10-07 12:59:10 UTC
Created attachment 36811 [details]
clean up IntList code

The IntList code looked somewhat obfuscated to me (like a literal translation of some functional code), so I cleaned it up in some places. I rearranged some of the loops to a more canonical form, which could in theory also be of benefit performance wise. I did not have measured this one on its won, but together with the other patches time for a full `ant jar` after `ant clean` went down 20 seconds on my machine, so at least it should not be worse than before.
Comment 5 Axel Howind 2019-10-07 13:02:09 UTC
Created attachment 36812 [details]
in some places, Objects.equals could be used instead

Please apply after or together with the other patches, as there might be side effects (because I removed one or two package private XXXequals() methods in this ptach).
Comment 6 Axel Howind 2019-10-07 13:20:42 UTC
Created attachment 36813 [details]
Strings: Replace StringBuffer with StringBuilder, use indexOf(char) instead of indexOf(String) where possible
Comment 7 Dominik Stadler 2019-10-26 05:20:02 UTC
Applied "BigDecimal: use enum args instead of integers (deprecated in Java 9)" via 1868897
Comment 8 Dominik Stadler 2019-10-26 05:40:24 UTC
Applied "BigDecimal: use enum args instead of integers (deprecated in Java 9)" via r1868897
Comment 9 Andreas Beeker 2019-10-26 19:28:39 UTC
Remove references to DatatypeConverter via r1868953
Comment 10 Axel Howind 2019-11-02 10:29:39 UTC
Hi, what's the current status of this? I see that the BigDecimal patch has been applied. I am waiting for you to catch up before I create any more patches. If the patches are too big or I should change something else, just give a feedback here.
Comment 11 Axel Howind 2019-11-17 08:46:51 UTC
Applied "use zero size arg to toArray(), use Collection.addAll()" via 1869919
Comment 12 Axel Howind 2020-02-20 15:06:04 UTC
Applied "clean up IntList code" via r1874257
Comment 13 Axel Howind 2020-02-20 15:53:14 UTC
Applied the remaining bits of "use indexOf(char) instead of indexOf(String) where possible" via r1874262
Comment 14 Axel Howind 2020-02-20 16:02:48 UTC
If I didn't overlook something, all changes should be in now. I will close this issue.