naruto-lgtm commented on code in PR #1580:
URL: https://github.com/apache/poi/pull/1580#discussion_r4651343626


##########
poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java:
##########
@@ -324,6 +324,21 @@ public void removeRow(Row row) {
                 _firstrow = -1;
                 _lastrow = -1;
             }
+
+            // also remove any comment located in that row
+            removeCommentsInRow(hrow.getRowNum());
+        }
+    }
+
+    private void removeCommentsInRow(int rowNum) {
+        final HSSFPatriarch patriarch = getDrawingPatriarch();
+        if (patriarch == null) {
+            return;
+        }
+        for (final HSSFShape shape : new ArrayList<>(patriarch.getChildren())) 
{

Review Comment:
   Good catch, grouped comments were missed. removeRow now finds the comment's 
own container and removes it there, so a comment inside an HSSFShapeGroup goes 
away with its NoteRecord as well.
   
   The per-call copy of the child list is gone too: the row's comments come 
from the existing recursive walk, and that walk only runs when the cheap 
NoteRecord check below says this row has a comment, so rows without one cost 
nothing.



##########
poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java:
##########
@@ -324,6 +324,21 @@ public void removeRow(Row row) {
                 _firstrow = -1;
                 _lastrow = -1;
             }
+
+            // also remove any comment located in that row
+            removeCommentsInRow(hrow.getRowNum());
+        }
+    }
+
+    private void removeCommentsInRow(int rowNum) {
+        final HSSFPatriarch patriarch = getDrawingPatriarch();

Review Comment:
   Agreed, that was too eager. There's a cheap check in front of it now: while 
the drawing records have not been aggregated the NoteRecords are still plain 
records on the sheet, so removeRow scans those for the row and only goes near 
the patriarch when one matches. Once an EscherAggregate is there the walk is 
free, so the check short-circuits. 
removeRowWithoutACommentDoesNotAggregateTheDrawing covers a sheet with a 
picture and no comment.



##########
poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java:
##########
@@ -324,6 +324,21 @@ public void removeRow(Row row) {
                 _firstrow = -1;
                 _lastrow = -1;
             }
+
+            // also remove any comment located in that row
+            removeCommentsInRow(hrow.getRowNum());

Review Comment:
   Right. The comments now go before the row: the identity check uses 
_rows.get(key) and the removal happens ahead of the _rows/_sheet mutation, so a 
drawing that cannot be read leaves the sheet as it was instead of half applied.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to