ASF Bugzilla – Attachment 32003 Details for
Bug 56958
[PATCH] XSSFSheet.validateArrayFormulas incorrect and incomplete range intersection check
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
fixes incorrect and incomplete intersection check
56958.patch (text/plain), 7.65 KB, created by
Yaniv Kunda
on 2014-09-11 11:53:18 UTC
(
hide
)
Description:
fixes incorrect and incomplete intersection check
Filename:
MIME Type:
Creator:
Yaniv Kunda
Created:
2014-09-11 11:53:18 UTC
Size:
7.65 KB
patch
obsolete
>Index: src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (revision 1624018) >+++ src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (revision ) >@@ -670,12 +670,9 @@ > > if (cell.isPartOfArrayFormulaGroup()) { > CellRangeAddress arrayRange = cell.getArrayFormulaRange(); >- if (arrayRange.getNumberOfCells() > 1 && >- (arrayRange.isInRange(region.getFirstRow(), region.getFirstColumn()) || >- arrayRange.isInRange(region.getFirstRow(), region.getFirstColumn()))) { >- String msg = "The range " + region.formatAsString() + " intersects with a multi-cell array formula. " + >- "You cannot merge cells of an array."; >- throw new IllegalStateException(msg); >+ if (arrayRange.getNumberOfCells() > 1 && arrayRange.intersects(region)) { >+ throw new IllegalStateException("The range " + region.formatAsString() >+ + " intersects with a multi-cell array formula. You cannot merge cells of an array."); > } > } > } >Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (revision 1624018) >+++ src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (revision ) >@@ -304,12 +304,9 @@ > > if(cell.isPartOfArrayFormulaGroup()){ > CellRangeAddress arrayRange = cell.getArrayFormulaRange(); >- if (arrayRange.getNumberOfCells() > 1 && >- ( arrayRange.isInRange(region.getFirstRow(), region.getFirstColumn()) || >- arrayRange.isInRange(region.getFirstRow(), region.getFirstColumn())) ){ >- String msg = "The range " + region.formatAsString() + " intersects with a multi-cell array formula. " + >- "You cannot merge cells of an array."; >- throw new IllegalStateException(msg); >+ if (arrayRange.getNumberOfCells() > 1 && arrayRange.intersects(region)) { >+ throw new IllegalStateException("The range " + region.formatAsString() >+ + " intersects with a multi-cell array formula. You cannot merge cells of an array."); > } > } > } >Index: src/java/org/apache/poi/ss/util/CellRangeAddressBase.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/java/org/apache/poi/ss/util/CellRangeAddressBase.java (revision 1624018) >+++ src/java/org/apache/poi/ss/util/CellRangeAddressBase.java (revision ) >@@ -23,7 +23,7 @@ > /** > * See OOO documentation: excelfileformat.pdf sec 2.5.14 - 'Cell Range Address'<p/> > * >- * Common subclass of 8-bit and 16-bit versions >+ * Common superclass of 8-bit and 16-bit versions > * > * @author Josh Micich > */ >@@ -124,9 +124,22 @@ > public boolean isInRange(int rowInd, int colInd) { > return _firstRow <= rowInd && rowInd <= _lastRow && > _firstCol <= colInd && colInd <= _lastCol; >+ } >+ >+ /** >+ * Determines if the given range intersects with the this range. >+ * >+ * @param other other range >+ * @return True if the ranges intersect, false otherwise. >+ */ >+ public boolean intersects(CellRangeAddressBase other) { >+ return this._firstRow <= other._lastRow && >+ this._firstCol <= other._lastCol && >+ other._firstRow <= this._lastRow && >+ other._firstCol <= this._lastCol; >- } >+ } > >- /** >+ /** > * @param firstCol column number for the upper left hand corner > */ > public final void setFirstColumn(int firstCol) { >Index: src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java >IDEA additional info: >Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP ><+>UTF-8 >=================================================================== >--- src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java (revision 1624018) >+++ src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetUpdateArrayFormulas.java (revision ) >@@ -25,6 +25,8 @@ > import org.apache.poi.ss.util.CellRangeAddress; > import org.apache.poi.ss.util.CellReference; > >+import java.util.Arrays; >+ > /** > * Common superclass for testing usermodel API for array formulas.<br/> > * Formula evaluation is not tested here. >@@ -438,19 +440,42 @@ > assertTrue(scell.isPartOfArrayFormulaGroup()); > assertEquals(1, sheet.getNumMergedRegions()); > >- //we cannot merge cells included in an array formula >+ // we cannot merge cells included in an array formula > CellRange<? extends Cell> mrange = >- sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C1:C3")); >- CellRangeAddress cra = CellRangeAddress.valueOf("C1:C3"); >+ sheet.setArrayFormula("A1:A3*B1:B3", CellRangeAddress.valueOf("C2:F5")); >+ for (String ref : Arrays.asList( >+ "C2:F5", // identity >+ "D3:E4", "B1:G6", // contains >+ "B1:C2", "F1:G2", "F5:G6", "B5:C6", // 1x1 corner intersection >+ "B1:C6", "B1:G2", "F1:G6", "B5:G6", // 1-row/1-column intersection >+ "B1:D3", "E1:G3", "E4:G6", "B4:D6", // 2x2 corner intersection >+ "B1:D6", "B1:G3", "E1:G6", "B4:G6" // 2-row/2-column intersection >+ )) { >+ CellRangeAddress cra = CellRangeAddress.valueOf(ref); >- try { >- sheet.addMergedRegion(cra); >- fail("expected exception"); >- } catch (IllegalStateException e){ >+ try { >+ sheet.addMergedRegion(cra); >+ fail("expected exception"); >+ } catch (IllegalStateException e){ >- String msg = "The range "+cra.formatAsString()+" intersects with a multi-cell array formula. You cannot merge cells of an array."; >- assertEquals(msg, e.getMessage()); >+ String expectedMessage = "The range " + cra.formatAsString() >+ + " intersects with a multi-cell array formula. You cannot merge cells of an array."; >+ assertEquals(expectedMessage, e.getMessage()); >- } >+ } >+ } >+ int expectedNumMergedRegions = 1; > //the number of merged regions remains the same >- assertEquals(1, sheet.getNumMergedRegions()); >+ assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions()); >+ >+ // we can merge non-intersecting cells >+ for (String ref : Arrays.asList("C1:F1", "G2:G5", "C6:F6", "B2:B5", "H7:J9")) { >+ CellRangeAddress cra = CellRangeAddress.valueOf(ref); >+ try { >+ sheet.addMergedRegion(cra); >+ expectedNumMergedRegions++; >+ assertEquals(expectedNumMergedRegions, sheet.getNumMergedRegions()); >+ } catch (IllegalStateException e) { >+ fail("did not expect exception"); >+ } >+ } > } > > public void testModifyArrayCells_shiftRows(){
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 56958
:
32001
| 32003