poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r998967 - in /poi/trunk: src/documentation/content/xdocs/status.xml src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java test-data/spreadsheet/49931.xls
Date Mon, 20 Sep 2010 16:00:50 GMT
Author: nick
Date: Mon Sep 20 16:00:50 2010
New Revision: 998967

URL: http://svn.apache.org/viewvc?rev=998967&view=rev
Log:
Fix bug #49931 - Avoid concurrency problems when re-ordering multiple HSSF header records
for a PageSettingsBlock

Added:
    poi/trunk/test-data/spreadsheet/49931.xls   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=998967&r1=998966&r2=998967&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Sep 20 16:00:50 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta3" date="2010-??-??">
+           <action dev="poi-developers" type="fix">49931 - Avoid concurrency problems
when re-ordering multiple HSSF header records for a PageSettingsBlock</action>
            <action dev="poi-developers" type="fix">49765 - Fix XWPFDocument.addPicture
so that it correctly sets up relationships</action>
            <action dev="poi-developers" type="fix">48018 - Improve HWPF handling of
lists in documents read and then saved, by preserving order better</action>
            <action dev="poi-developers" type="fix">49820 - Fix HWPF paragraph levels,
so that outline levels can be properly fetched</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java?rev=998967&r1=998966&r2=998967&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java Mon Sep
20 16:00:50 2010
@@ -18,6 +18,7 @@
 package org.apache.poi.hssf.record.aggregates;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Arrays;
@@ -639,7 +640,7 @@ public final class PageSettingsBlock ext
 
     /**
      * Some apps can define multiple HeaderFooterRecord records for a sheet.
-     * When saving such a file Excel 2007 re-positiones them according to the followig rules:
+     * When saving such a file Excel 2007 re-positions them according to the following rules:
      *  - take a HeaderFooterRecord and read 16-byte GUID at offset 12. If it is zero,
      *    it means the current sheet and the given HeaderFooterRecord belongs to this PageSettingsBlock
      *  - If GUID is not zero then search in preceding CustomViewSettingsRecordAggregates.
@@ -649,10 +650,13 @@ public final class PageSettingsBlock ext
      * @param sheetRecords the list of sheet records read so far
      */
     public void positionRecords(List<RecordBase> sheetRecords) {
+        // Take a copy to loop over, so we can update the real one
+        //  without concurrency issues
+        List<HeaderFooterRecord> hfRecordsToIterate = new ArrayList<HeaderFooterRecord>(_sviewHeaderFooters);
+       
         // loop through HeaderFooterRecord records having not-empty GUID and match them with
         // CustomViewSettingsRecordAggregate blocks having UserSViewBegin with the same GUID
-        for (final Iterator<HeaderFooterRecord> it = _sviewHeaderFooters.iterator();
it.hasNext(); ) {
-            final HeaderFooterRecord hf = it.next();
+        for(final HeaderFooterRecord hf : hfRecordsToIterate) {
             for (RecordBase rb : sheetRecords) {
                 if (rb instanceof CustomViewSettingsRecordAggregate) {
                     final CustomViewSettingsRecordAggregate cv = (CustomViewSettingsRecordAggregate)
rb;
@@ -663,7 +667,7 @@ public final class PageSettingsBlock ext
                                 byte[] guid2 = hf.getGuid();
                                 if (Arrays.equals(guid1, guid2)) {
                                     cv.append(hf);
-                                    it.remove();
+                                    _sviewHeaderFooters.remove(hf);
                                 }
                             }
                         }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=998967&r1=998966&r2=998967&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Mon Sep 20 16:00:50
2010
@@ -1857,6 +1857,15 @@ if(1==2) {
             }
         }
         assertTrue(namedStyles.containsAll(collecteddStyles));
-
     }    
+    
+    /**
+     * Regression with the PageSettingsBlock
+     */
+    public void test49931() throws Exception {
+       HSSFWorkbook wb = openSample("49931.xls");
+       
+       assertEquals(1, wb.getNumberOfSheets());
+       assertEquals("Foo", wb.getSheetAt(0).getRow(0).getCell(0).getRichStringCellValue().toString());
+    }
 }

Added: poi/trunk/test-data/spreadsheet/49931.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/49931.xls?rev=998967&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/49931.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message