Created attachment 38422 [details] Example excel where this problem occurs I have an excel file that when iterating through and even just calling getCellComment throws an exception when I try to write it out. I have attached an example excel. The exception is: class org.apache.poi.hssf.record.DSFRecord cannot be cast to class org.apache.poi.hssf.record.TabIdRecord (org.apache.poi.hssf.record.DSFRecord and org.apache.poi.hssf.record.TabIdRecord are in unnamed module of loader 'app') I am using POI 5.2.3. Here is some code that can be used to reproduce the error: try (FileInputStream fileInputStream = new FileInputStream(Path.of("put path to xls here").toFile()); Workbook workbook = new HSSFWorkbook(fileInputStream)) { for (Sheet sheet : workbook) { for (Row row : sheet) { for (Cell cell : row) { cell.getCellComment(); // or even cell.removeCellComment(); } } } FileOutputStream fos = new FileOutputStream(Files.createTempFile("modified", ".xsl").toFile()); workbook.write(fos); fos.close(); } catch (Exception e) { System.out.println(e.getMessage()); }
I added r1905943 - let's see if that breaks anything else. It doesn't fix the underlying issue as to why creating a HSSFPatriarch breaks this workbook. But there is no need to create a HSSFPatriarch in this use case.
Seems the reported issue is fixed by the changes, let's reopen or create new issues if other files cause more issues.