From 3300d541793ddd98aabba61238e5fb4ffaed1882 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Thu, 22 Sep 2016 07:50:33 +0000 Subject: [PATCH] bug 59687: correctly delete comments from rows when removing a row and the workbook contains empty rows above the deleted row; patch from Greg Woolsey git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1761861 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/xssf/usermodel/XSSFSheet.java | 10 ++++++---- .../org/apache/poi/xssf/usermodel/TestXSSFSheet.java | 3 +-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 8b9746489f..bc2f071bea 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -1928,15 +1928,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { } // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory - final Integer rownumI = new Integer(row.getRowNum()); // NOSONAR - int idx = _rows.headMap(rownumI).size(); - _rows.remove(rownumI); + final int rowNum = row.getRowNum(); + final Integer rowNumI = new Integer(rowNum); // NOSONAR + // this is not the physical row number! + final int idx = _rows.headMap(rowNumI).size(); + _rows.remove(rowNumI); worksheet.getSheetData().removeRow(idx); // also remove any comment located in that row if(sheetComments != null) { for (CellAddress ref : getCellComments().keySet()) { - if (ref.getRow() == idx) { + if (ref.getRow() == rowNum) { sheetComments.removeComment(ref); } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index 34ae2cfc40..24c1d72375 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -2022,8 +2022,7 @@ public final class TestXSSFSheet extends BaseTestXSheet { } // bug 59687: XSSFSheet.RemoveRow doesn't handle row gaps properly when removing row comments - // This test is currently failing (thus expected AssertionError). When this bug is fixed, no error should be thrown. - @Test(expected=AssertionError.class) + @Test public void testRemoveRowWithCommentAndGapAbove() throws IOException { final Workbook wb = _testDataProvider.openSampleWorkbook("59687.xlsx"); final Sheet sheet = wb.getSheetAt(0); -- 2.39.5