Bug 53369

Summary: testDateFormat(org.apache.poi.ss.format.TestCellFormatPart)junit.framework.ComparisonFailure: format "org.apache.poi.ss.format.CellFormatPart@dbcd0e" expected:<"11-10-[]52"> but was:<"11-10-[19]52">
Product: POI Reporter: Orion Poplawski <orion>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.8-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: jdk17 patch

Description Orion Poplawski 2012-06-06 03:32:59 UTC
Trying to build apache-poi 3.8 for Fedora 17 with openjdk 1.7.0 I'm getting the following failure:

compile-ooxml-lite:
     [java] Collecting unit tests from /export/home/orion/fedora/apache-poi/poi-3.8/build/ooxml-test-classes
     [java] ......F...................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] .........................................
     [java] ...................................
     [java] Time: 163.944
     [java] There was 1 failure:
     [java] 1) testDateFormat(org.apache.poi.ss.format.TestCellFormatPart)junit.framework.ComparisonFailure: format "org.apache.poi.ss.format.CellFormatPart@dbcd0e" expected:<"11-10-[]52"> but was:<"11-10-[19]52">
     [java]     at org.apache.poi.ss.format.CellFormatTestBase$CellValue.equivalent(CellFormatTestBase.java:95)
     [java]     at org.apache.poi.ss.format.CellFormatTestBase.tryColor(CellFormatTestBase.java:247)
     [java]     at org.apache.poi.ss.format.CellFormatTestBase.tryFormat(CellFormatTestBase.java:221)
     [java]     at org.apache.poi.ss.format.CellFormatTestBase.runFormatTests(CellFormatTestBase.java:130)
     [java]     at org.apache.poi.ss.format.TestCellFormatPart.testDateFormat(TestCellFormatPart.java:77)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     [java]     at org.apache.poi.util.OOXMLLite.build(OOXMLLite.java:103)
     [java]     at org.apache.poi.util.OOXMLLite.main(OOXMLLite.java:78)
     [java] 
     [java] FAILURES!!!
     [java] Tests run: 814,  Failures: 1,  Errors: 0



    [junit] Running org.apache.poi.ss.format.TestCellFormatPart
    [junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 1.732 sec

Let me know if there is anything else I can provide.
Comment 1 Yegor Kozlov 2012-06-06 07:04:51 UTC
It looks like POI does not build on JDK 1.7

I was able to reproduce the trouble with Oracle JDK 1.7.01. Same test fails, only the message is a bit different:

    [java] There was 1 failure:
    [java] 1) testDateFormat(org.apache.poi.ss.format.TestCellFormatPart)junit.framework.ComparisonFailure: format "org
apache.poi.ss.format.CellFormatPart@289e637e" expected:<......> but was:<...19...>
    [java]     at org.apache.poi.ss.format.CellFormatTestBase$CellValue.equivalent(CellFormatTestBase.java:95)
    [java]     at org.apache.poi.ss.format.CellFormatTestBase.tryColor(CellFormatTestBase.java:247)
    [java]     at org.apache.poi.ss.format.CellFormatTestBase.tryFormat(CellFormatTestBase.java:221)
    [java]     at org.apache.poi.ss.format.CellFormatTestBase.runFormatTests(CellFormatTestBase.java:130)
    [java]     at org.apache.poi.ss.format.TestCellFormatPart.testDateFormat(TestCellFormatPart.java:77)
    [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [java]     at org.apache.poi.util.OOXMLLite.build(OOXMLLite.java:103)
    [java]     at org.apache.poi.util.OOXMLLite.main(OOXMLLite.java:78)
    [java]
Comment 2 Nick Burch 2012-06-06 09:11:52 UTC
I can confirm the same issue with OpenJDK 1.7

java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.1pre) (7~u3-2.1.1~pre1-1ubuntu3)
OpenJDK 64-Bit Server VM (build 22.0-b10, mixed mode)

    [junit] Running org.apache.poi.ss.format.TestCellFormatPart
    [junit] Tests run: 3, Failures: 1, Errors: 0, Time elapsed: 0.247 sec

junit.framework.ComparisonFailure: format "org.apache.poi.ss.format.CellFormatPart@416ba050" expected:<......> but was:<...19...>

Is anyone able to get their IDE running with Java 1.7, and debug / step in to work out exactly what is going wrong and where?
Comment 3 Yegor Kozlov 2012-06-06 09:16:31 UTC
I put this bug in my punch list.
Comment 4 jack 2012-07-12 06:24:09 UTC
I can confirm the same issue with JDK1.7
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)


It's coused by SimpleDateFormat format.

new java.text.SimpleDateFormat("d-M-y").format(new Date()) 
is  "12-7-2012",
but in excel the format result is "12-7-12".

Could fixed in DatePartHandler(org.apache.poi.ss.format.CellDateFormatter).
Comment 5 jack 2012-07-12 08:08:29 UTC
I fixed it simply by change 
dateFmt = new SimpleDateFormat(descBuf.toString());
to 
dateFmt = new SimpleDateFormat(
  descBuf.toString().replaceAll("((y)(?!y))(?<!yy)", "yy"),LOCALE.US);
in org.apache.poi.ss.format.CellDateFormatter at line 153.
Comment 6 Orion Poplawski 2012-07-13 23:08:25 UTC
Created attachment 29059 [details]
jdk17 patch

That fixes the build for me.  Attached a patch.
Comment 7 Yegor Kozlov 2012-07-21 10:08:37 UTC
Thanks for the patch, applied in r1364058

Regards,
Yegor