Author: kiwiwings
Date: Fri Sep  5 19:07:32 2014
New Revision: 1622759

URL: http://svn.apache.org/r1622759
Log:
Bug 56914 - XSSFRowShifter.updateConditionalFormatting throws IOOBE when there 
are more than 1 CTConditionalFormatting 

Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java
    
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
    
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: 
http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1622759&r1=1622758&r2=1622759&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Fri Sep  5 19:07:32 2014
@@ -38,6 +38,7 @@
     </devs>
 
     <release version="3.11-beta3" date="2014-??-??">
+        <action dev="PD" type="fix" 
fixes-bug="56914">XSSFRowShifter.updateConditionalFormatting throws IOOBE when 
there are more than 1 CTConditionalFormatting</action>
         <action dev="PD" type="fix" fixes-bug="56913">Replace usages of 
o.a.p.util.ArrayUtil.copyOf* methods with replacements from j.u.Arrays</action>
         <action dev="PD" type="fix" fixes-bug="51483">XSSF locking of specific 
features not working</action>
         <action dev="PD" type="fix" fixes-bug="48195">Formulas: Fix incorrect 
evaluation of IF() with ROW()/COLUMN() as else-result.</action>

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java?rev=1622759&r1=1622758&r2=1622759&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java
 (original)
+++ 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheetConditionalFormatting.java
 Fri Sep  5 19:07:32 2014
@@ -131,19 +131,13 @@ public class XSSFSheetConditionalFormatt
         if (cfRules.length > 3) {
             throw new IllegalArgumentException("Number of rules must not 
exceed 3");
         }
-        XSSFConditionalFormattingRule[] hfRules;
-        if(cfRules instanceof XSSFConditionalFormattingRule[]) hfRules = 
(XSSFConditionalFormattingRule[])cfRules;
-        else {
-            hfRules = new XSSFConditionalFormattingRule[cfRules.length];
-            System.arraycopy(cfRules, 0, hfRules, 0, hfRules.length);
-        }
+
         CellRangeAddress[] mergeCellRanges = 
CellRangeUtil.mergeCellRanges(regions);
         CTConditionalFormatting cf = 
_sheet.getCTWorksheet().addNewConditionalFormatting();
         List<String> refs = new ArrayList<String>();
         for(CellRangeAddress a : mergeCellRanges) refs.add(a.formatAsString());
         cf.setSqref(refs);
 
-
         int priority = 1;
         for(CTConditionalFormatting c : 
_sheet.getCTWorksheet().getConditionalFormattingArray()){
             priority += c.sizeOfCfRuleArray();

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java?rev=1622759&r1=1622758&r2=1622759&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
 (original)
+++ 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFRowShifter.java
 Fri Sep  5 19:07:32 2014
@@ -226,12 +226,12 @@ public final class XSSFRowShifter {
         XSSFWorkbook wb = sheet.getWorkbook();
         int sheetIndex = wb.getSheetIndex(sheet);
 
-
         XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb);
         CTWorksheet ctWorksheet = sheet.getCTWorksheet();
-        int cfCount = ctWorksheet.sizeOfConditionalFormattingArray();
-        for(int j = 0; j< cfCount; j++){
-            CTConditionalFormatting cf = 
ctWorksheet.getConditionalFormattingArray(j);
+        CTConditionalFormatting[] conditionalFormattingArray = 
ctWorksheet.getConditionalFormattingArray();
+        // iterate backwards due to possible calls to 
ctWorksheet.removeConditionalFormatting(j)
+        for (int j = conditionalFormattingArray.length - 1; j >= 0; j--) {
+            CTConditionalFormatting cf = conditionalFormattingArray[j];
 
             ArrayList<CellRangeAddress> cellRanges = new 
ArrayList<CellRangeAddress>();
             for (Object stRef : cf.getSqref()) {
@@ -267,9 +267,9 @@ public final class XSSFRowShifter {
             }
 
             for(CTCfRule cfRule : cf.getCfRuleArray()){
-                int formulaCount = cfRule.sizeOfFormulaArray();
-                for (int i = 0; i < formulaCount; i++) {
-                    String formula = cfRule.getFormulaArray(i);
+                String[] formulaArray = cfRule.getFormulaArray();
+                for (int i = 0; i < formulaArray.length; i++) {
+                    String formula = formulaArray[i];
                     Ptg[] ptgs = FormulaParser.parse(formula, fpb, 
FormulaType.CELL, sheetIndex);
                     if (shifter.adjustFormula(ptgs, sheetIndex)) {
                         String shiftedFmla = 
FormulaRenderer.toFormulaString(fpb, ptgs);

Modified: 
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java?rev=1622759&r1=1622758&r2=1622759&view=diff
==============================================================================
--- 
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
 (original)
+++ 
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
 Fri Sep  5 19:07:32 2014
@@ -390,7 +390,6 @@ public abstract class BaseTestConditiona
     }
 
     public void testShiftRows() {
-
         Workbook wb = _testDataProvider.createWorkbook();
         Sheet sheet = wb.createSheet();
 
@@ -403,30 +402,42 @@ public abstract class BaseTestConditiona
 
         PatternFormatting patternFmt = rule1.createPatternFormatting();
         patternFmt.setFillBackgroundColor(IndexedColors.YELLOW.index);
-        ConditionalFormattingRule [] cfRules = { rule1, };
+
+        ConditionalFormattingRule rule2 = 
sheetCF.createConditionalFormattingRule(
+                ComparisonOperator.BETWEEN, "SUM(A10:A15)", "1+SUM(B16:B30)");
+        BorderFormatting borderFmt = rule2.createBorderFormatting();
+        borderFmt.setBorderDiagonal((short) 2);
 
         CellRangeAddress [] regions = {
             new CellRangeAddress(2, 4, 0, 0), // A3:A5
         };
-        sheetCF.addConditionalFormatting(regions, cfRules);
+        sheetCF.addConditionalFormatting(regions, rule1);
+        sheetCF.addConditionalFormatting(regions, rule2);
 
         // This row-shift should destroy the CF region
         sheet.shiftRows(10, 20, -9);
         assertEquals(0, sheetCF.getNumConditionalFormattings());
 
         // re-add the CF
-        sheetCF.addConditionalFormatting(regions, cfRules);
+        sheetCF.addConditionalFormatting(regions, rule1);
+        sheetCF.addConditionalFormatting(regions, rule2);
 
         // This row shift should only affect the formulas
         sheet.shiftRows(14, 17, 8);
-        ConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);
-        assertEquals("SUM(A10:A23)", cf.getRule(0).getFormula1());
-        assertEquals("1+SUM(B24:B30)", cf.getRule(0).getFormula2());
+        ConditionalFormatting cf1 = sheetCF.getConditionalFormattingAt(0);
+        assertEquals("SUM(A10:A23)", cf1.getRule(0).getFormula1());
+        assertEquals("1+SUM(B24:B30)", cf1.getRule(0).getFormula2());
+        ConditionalFormatting cf2 = sheetCF.getConditionalFormattingAt(1);
+        assertEquals("SUM(A10:A23)", cf2.getRule(0).getFormula1());
+        assertEquals("1+SUM(B24:B30)", cf2.getRule(0).getFormula2());
 
         sheet.shiftRows(0, 8, 21);
-        cf = sheetCF.getConditionalFormattingAt(0);
-        assertEquals("SUM(A10:A21)", cf.getRule(0).getFormula1());
-        assertEquals("1+SUM(#REF!)", cf.getRule(0).getFormula2());
+        cf1 = sheetCF.getConditionalFormattingAt(0);
+        assertEquals("SUM(A10:A21)", cf1.getRule(0).getFormula1());
+        assertEquals("1+SUM(#REF!)", cf1.getRule(0).getFormula2());
+        cf2 = sheetCF.getConditionalFormattingAt(1);
+        assertEquals("SUM(A10:A21)", cf2.getRule(0).getFormula1());
+        assertEquals("1+SUM(#REF!)", cf2.getRule(0).getFormula2());
     }
 
     protected void testRead(String filename){



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to