title: XmlValueDisconnectedException when getting row index (getRowNum())
body: <p>In my code I am going through an XLSX-file row by row, validating them against a database with Apache POI 4.1.0. If I find a incorrect row I will "mark" them for deletion by adding it to the the <code>List&lt;XSSFRow&gt; toRemove</code>. After iterating over every row this small method is supposed to remove the rows marked for deletion:</p>
  
  <pre><code>ListIterator&lt;XSSFRow&gt; rowIterator = toRemove.listIterator(toRemove.size());
  
  while (rowIterator.hasPrevious()) {
      XSSFRow row = rowIterator.previous();
      if (row != null &amp;&amp; row.getSheet() == sheet) {
          int lastRowNum = sheet.getLastRowNum();
          int rowIndex = row.getRowNum();
  
          if (rowIndex == lastRowNum) {
              sheet.removeRow(row);
          } else if (rowIndex &gt;= 0 &amp;&amp; rowIndex &lt; lastRowNum) {
              sheet.removeRow(row);
  
          } else {
              System.out.println("\u001B[31mERROR: Removal failed because row " + rowIndex + " is out of bounds\u001B[0m");
          }
          System.out.println("Row " + rowIndex + " successfully removed");
      } else {
          System.out.println("Row skipped in removal because it was null already");
      }
  }
  </code></pre>
  
  <p>But for some unknown reason it removes all rows perfectly and then throws a XmlValueDisconnectedException when getting the row index (<code>getRowNum()</code>) of the last (first added) row.</p>
  
  <p>Relevant part of the Stacktrace:</p>
  
  <pre><code>org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
      at org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1258)
      at org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTRowImpl.getR(Unknown Source)
      at org.apache.poi.xssf.usermodel.XSSFRow.getRowNum(XSSFRow.java:400)
      at Overview.removeRows(Overview.java:122)
  </code></pre>
  
  <p>EDIT: I also tried changing the iteration process (see below) but the error stays the same.</p>
  
  <pre><code>for (XSSFRow row : toRemove) {
     // same code as above without iterator and while
  }
  </code></pre>