poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Axel Howind <a...@dua3.com>
Subject [PATCH] Use of Hashtable in POI codebase
Date Wed, 22 Jun 2016 20:50:13 GMT
When looking at the current source, I noticed Hashtable still being used 
in a number of places. Is there any reason for not replacing all these 
hashtable instances with HashMap (besides TestContentType.java failing, 
see below)?

I attach a patch that replaces Hashtable instantiations with HashMap and 
Hashtable declarations with Map (the common interface). Current git 
tests pass with this patch applied.

The only case where I left Hashtable in is ContentType.java because 
replacing that instance leads to a junit failure:

Testcase: testFileWithContentTypeParams took 0.004 sec
     FAILED
expected:<...cation/x-resqml+xml;[version=2.0;type=obj_global1dCrs]> but 
was:<...cation/x-resqml+xml;[type=obj_global1dCrs;version=2.0]>
junit.framework.ComparisonFailure: 
expected:<...cation/x-resqml+xml;[version=2.0;type=obj_global1dCrs]> but 
was:<...cation/x-resqml+xml;[type=obj_global1dCrs;version=2.0]>
     at 
org.apache.poi.openxml4j.opc.TestContentType.testFileWithContentTypeParams(TestContentType.java:203)

The failing test is this one:
assertEquals(typeResqml+";version=2.0;type=obj_global1dCrs", 
part.getContentTypeDetails().toString());

part is of type org.apache.poi.openxml4j.opc.PackagePart and toString() 
just concatenates all the entries contained in the parameters attribute 
(Hashtable) together by iterating over its entryset.

This is rather fragile and could break anytime since AFAIK the order in 
which hashtable/HashMap entries are returned is not guaranteed and could 
change with any (minor) Java release.

Suggestions:
-leave the hashtable in
-use a LinkedHashMap for 
org.apache.poi.openxml4j.opc.PackagePart.parameters to ensure consistent 
ordering
-change the test case not to test for String equality.

What do you think?

Axel.


Mime
View raw message