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 2009/03/18 19:42:08 UTC

DO NOT REPLY [Bug 46874] New: org.apache.poi.hssf.usermodel.HSSFWorkbook.getCellStyleAt() method calls ...model.Workbook.getExFormatAt() with wrong signature & crashes.

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

           Summary: org.apache.poi.hssf.usermodel.HSSFWorkbook.getCellStyl
                    eAt() method calls ...model.Workbook.getExFormatAt()
                    with wrong signature & crashes.
           Product: POI
           Version: 3.2-FINAL
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: ErrorMessage
          Severity: normal
          Priority: P2
         Component: HSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: gmortellwork@gmail.com


Overview:
---------------------------------------------
org.apache.poi.hssf.usermodel.HSSFWorkbook.getCellStyleAt() method calls the
org.apache.poi.hssf.model.Workbook.getExFormatAt() method with a short, when it
requires an integer index.   This results in the code crashing (see stack trace
below).


Background -
----------------------------------------------
This is my first time reporting a bug, so I apologize in advance if I'm missing
anything.

I am trying to create a java app to read in an Excel spreadsheet & split it out
into multiple spreadsheets, based upon key data.   To do this I need to clone
the CellStyles from the input workbook to each of the output workbooks, so
dates and currency formats will be the same in the output spreadsheets as they
are in the input spreadsheet. 

Steps to Reproduce: My Code That Initializes Each Output Workbook -
-------------------------------------------------------------------
//Clone the input workbook's CellStyles into the output workbook's
CellStyles...

for (short i = 0 ; i <= inputHSSFWorkbook.getNumCellStyles() ; i++)
{
    LOG.info("Synchronizing input & output workbook CellStyles...i = " +i);
    if (i > numberOfCellStylesOut)
    {   //create a new CellStyle (blank) and add it to the W/B's CellStyle
table.
        outputHSSFWorkbook.createCellStyle();
    }

    // Now try to synchronize all of the input & output workbook's CellStyle's.
    // the 'outputHSSFWorkbook.getCellStyleAt(i)' piece below returns the
output workbook's
    // HSSFCellStyle object at index i.   Clone it from the input CellStyle at
index i.
   
outputHSSFWorkbook.getCellStyleAt(i).cloneStyleFrom(inputHSSFWorkbook.getCellStyleAt(i));
}

numberOfCellStylesOut = outputHSSFWorkbook.getNumCellStyles();
LOG.debug("After synchronizing Input & Output CellStyle's - The number of
CellStyles in this output workbook is " + numberOfCellStylesOut);

There were 28 CellStyles in the input workbook and 21 in the new output
workbook.  I would expect to now see 28 CellStyles in each output workbook

Actual Results: The Stack Trace From the Crash -
------------------------------------------------

    Exception in thread "main" java.lang.ClassCastException:
org.apache.poi.hssf.record.StyleRecord
        at org.apache.poi.hssf.model.Workbook.getExFormatAt(Workbook.java:742)
        at
org.apache.poi.hssf.usermodel.HSSFWorkbook.getCellStyleAt(HSSFWorkbook.java:1125)



Expected Results:
-----------------------------------------------
I expected the code to clone the CellStyles from the input workbook to each of
the output workbooks.


Build Date & Platform: 
-----------------------------------------------
I encountered this on both the 3.2-FINAL build and the 3.5-Beta5 builds.  I
think this will only happen on versions 3.2-FINAL and higher, since that is
when the cloneStyleFrom() methosd was available.  Here's the MANIFEST.MF file
from my POI jar...

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.5.0_13-b05 (Sun Microsystems Inc.)
Built-By: yegor
Specification-Title: Apache POI
Specification-Version: 3.2-FINAL-20081019
Specification-Vendor: Apache
Implementation-Title: Apache POI
Implementation-Version: 3.2-FINAL-20081019
Implementation-Vendor: Apache


Additional Information - The Apache POI HSSF Code - 
----------------------------------------------------
org.apache.poi.hssf.usermodel.HSSFWorkbook.getCellStyleAt() method passes a
short to the 
org.apache.poi.hssf.model.Workbook.getExFormatAt() method, which doesn't have a
signature to accept a short.   getExFormatAt()'s signature is for an int.

If the org.apache.poi.hssf.usermodel.HSSFWorkbook.getCellStyleAt() method
assigns its input short to an int, it could pass the int in the method call to
org.apache.poi.hssf.model.Workbook.getExFormatAt() method.  

I believe that this will work without crashing.   To be honest, I'm not as
experienced as most Java developers, so this might not be right.   You folks
would know better.

Hope this helps,

Gerald Mortell

-- 
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 46874] org.apache.poi.hssf.usermodel.HSSFWorkbook.getCellStyleAt() method calls ...model.Workbook.getExFormatAt() with wrong signature & crashes.

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


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

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




--- Comment #1 from Nick Burch <ni...@torchbox.com>  2009-03-24 10:00:08 PST ---
I'm almost certain that you have two copies of poi in your classpath, and
that's what is breaking things. I'd suggest you try the code in the faq for
checking where classes come from, and that ought to help you spot your two
conflicting versions

(It all works fine for me, and for all the unit tests)

-- 
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