Bug 46302 - [PATCH] HSSFCellStyle cloneStyleFrom always throws exception.
Summary: [PATCH] HSSFCellStyle cloneStyleFrom always throws exception.
Status: RESOLVED DUPLICATE of bug 47054
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows XP
: P2 regression with 2 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-26 15:12 UTC by Patrick Radtke
Modified: 2009-04-20 10:32 UTC (History)
0 users



Attachments
Patch that should solve a bug related to the cloneStyleFrom method of XSSFCellStyle class (and HSSFCellStyle as well) (1.49 KB, patch)
2008-11-27 01:06 UTC, lorenzo benvenuti
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Radtke 2008-11-26 15:12:05 UTC
CloneStyleFrom should only throw an exception if the passed in style is not HSSFCellStyle.


Note that there is also an issue with XSSFCellStyle cloneStyleFrom - it appears to call itself indefinitely when the input is of XSSFCellStyle.
Comment 1 lorenzo benvenuti 2008-11-27 01:06:27 UTC
Created attachment 22956 [details]
Patch that should solve a bug related to the cloneStyleFrom method of XSSFCellStyle class (and HSSFCellStyle as well)

I'm not so familiar with open source developing, so I don't know if this is the right way to proceed. If not, please excuse me. 
I came across a bug in XSSFCellStyle and consequently, in this bug. Probably I managed how to solve both (a first look at the generated xlsx seems to confirm that I was able to clone the style). You can find the changes I made to the sources in the attached patch. In XSSFCellStyle.java I tried to use the style used in HSSFCellStyle.java. I'm not sure it's an efficient, elegant or complete solution but I hope this can help.

Regards, 

Lorenzo Benvenuti
Comment 2 Patrick Radtke 2008-11-27 07:59:49 UTC
Lorenzo,

The only issue I see with the patch is for the XSSFCellStyle cloneStyleFrom() method. There is only a single cloneStyleFrom method in XSSFCellStyle (while HSSFCellStyle has two), therefor the XSSFCellStyle cloneStyleFrom method will call itself recursively and never return (while in HSSFCellStyle one of the methods calls the other)

Comment 3 Patrick Radtke 2008-11-27 08:08:30 UTC
Lorenzo,

My apologies. I didn't scroll down all the way on your patch. I see that you have included the second cloneStyleFrom method.

Do we need to set some of the other style variables like cellStyleXf?

Comment 4 lorenzo benvenuti 2008-11-27 23:24:24 UTC
Patrick,

actually I'm not sure that the "state" of the XSSFCellStyle is fully determined by the cellXf property. I just took a look at the copy() method and I thought the style representation was fully delegated to the cellXf bean while the other properties were just cellStyle "control" variables already set in the costructor when the current style (the one that is going to clone the source style) is created.
Please notice I might be wrong, probably the author of the XSSFCellStyle class would be helpful here.
Regarding the methods calling itself indefinitely, as you may have guessed, I used the overloaded method to mirror the HSSFCellStyle class implementation of the cloneStyleFrom method.
At last: I think the "return" clauses I added are necessary for avoiding the exception to be always thrown; actually I don't like using a "return" in the middle of a class (in this case I could have changed the "if" condition) but this was the less invasive change.

Hope this helps!

Lorenzo

Comment 5 Yegor Kozlov 2009-04-20 10:32:08 UTC
Should be fixed in r766755

Yegor

*** This bug has been marked as a duplicate of bug 47054 ***