Bug 40508 - [INFO NEEDED] ObjRecord#clone() is incorrect
Summary: [INFO NEEDED] ObjRecord#clone() is incorrect
Status: RESOLVED DUPLICATE of bug 31092
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: All All
: P1 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-14 09:05 UTC by TANAKA Yoshihiro
Modified: 2008-05-08 22:24 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description TANAKA Yoshihiro 2006-09-14 09:05:03 UTC
I got a exception as follow when copying sheet:

Caused by: java.util.ConcurrentModificationException
java.util.AbstractList$Itr.checkForComodification(AbstractList.java:449)
java.util.AbstractList$Itr.next(AbstractList.java:420)
org.apache.poi.hssf.record.ObjRecord.clone(ObjRecord.java:182)
org.apache.poi.hssf.model.Sheet.cloneSheet(Sheet.java:320)
org.apache.poi.hssf.usermodel.HSSFSheet.cloneSheet(HSSFSheet.java:114)
org.apache.poi.hssf.usermodel.HSSFWorkbook.cloneSheet(HSSFWorkbook.java:337)
 snip

It is caused by a bug of "clone" method in the "ObjRecord" class.
    public Object clone()
    {
        ObjRecord rec = new ObjRecord();
        rec.subrecords = new ArrayList();

        for ( Iterator iterator = subrecords.iterator(); iterator.hasNext(); )
            subrecords.add(( (Record) iterator.next() ).clone()); 

        return rec;
    }

"subrecords.add" must be "rec.subrecords.add" in the "for" block. I got correct
result after modification.
Comment 1 Avik Sengupta 2007-01-16 02:10:39 UTC
I dont want to add this patch without a testcase... seems risky to me. Could you
please supply a short testcase that triggers this bug? Thanks. 
Comment 2 Josh Micich 2008-05-08 22:24:07 UTC
Almost identical fix to bug 31092 (svn r353603)

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