I got the message : Exception in thread "main" org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Rule M2.4 exception : this error should NEVER happen! Please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach a file that triggers it, thanks! at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.getContentType(ContentTypeManager.java:343) at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.removeContentType(ContentTypeManager.java:256) at org.apache.poi.openxml4j.opc.OPCPackage.removePart(OPCPackage.java:943) at org.apache.poi.openxml4j.opc.PackagePart.getOutputStream(PackagePart.java:522) at org.apache.poi.xssf.usermodel.XSSFWorkbook.commit(XSSFWorkbook.java:1678) at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:341) at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:206) Since the file that triggers it is fairly big I'm attaching the code that triggers it. This code is the very beginning, the only lines before it are declarations and initializations. Written in Java 8 u 74. Good luck ! :) for(String folder : godine){ XSSFWorkbook wbTemp = new XSSFWorkbook(); wbTemp.createSheet(); FileOutputStream fo = new FileOutputStream(lokacijaResursa+"\\statistika-"+folder+".xlsx"); HashMap<String,Integer> pozicija = new HashMap<>(); napraviCelije(wbTemp,100,200); for(int i=1;i<=12;i++) { try { XSSFWorkbook mjesec = new XSSFWorkbook(new FileInputStream(new File(lokacijaResursa + "\\" + folder + "\\" + i + ".xlsx"))); XSSFSheet sheetMjesec = mjesec.getSheetAt(0); popuni(wbTemp, mjesec, pozicija, i); } catch (Exception ex){} } wbTemp.write(fo); fo.close(); XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(lokacijaResursa+"\\statistika-"+folder+".xlsx")); int numOfCells = 0; try{ for(int i=3;;i++){ Row r = wb.getSheetAt(0).getRow(1); Cell c = r.getCell(i,Row.CREATE_NULL_AS_BLANK); if(c.getCellType() == Cell.CELL_TYPE_BLANK) break; numOfCells++; } for(int i=2;;i++){ Row r = wb.getSheetAt(0).getRow(i); if(r.getCell(0,Row.CREATE_NULL_AS_BLANK).getCellType() == Cell.CELL_TYPE_BLANK) break; for(int j=3;j<numOfCells;j++){ Cell c = r.getCell(j,Row.CREATE_NULL_AS_BLANK); if(c.getCellType() == Cell.CELL_TYPE_BLANK) break; else c.setCellValue(0); } } } catch (NullPointerException ex){ System.out.println("Nema fajlova"); System.exit(0); } wb.close(); fo = new FileOutputStream(new File(lokacijaResursa+"\\statistika-"+folder+".xlsx")); wb.write(fo); fo.close(); }
What about the "and attach a file that triggers it" in the error message? Without a sample file that triggers the error, it is hard to say if the file is simply malformed or POI does not read the format correctly here.
Oops, sorry, just saw the additional part in the description.
*** Bug 59159 has been marked as a duplicate of this bug. ***
I did a short review of this report, the provided code still depends on the actual input-files, so we cannot really reproduce this without some sample files and preferably a self-sufficient unit-test which reproduces the problem more easily. This will make it much easier for others to reproduce and actually take a look at the problem.
> wb.close(); > fo = new FileOutputStream(new File(lokacijaResursa+"\\statistika-"+folder+".xlsx")); > wb.write(fo); You cannot use a workbook after it has been closed. Close your workbook after wb.write and your error should go away.
*** Bug 61297 has been marked as a duplicate of this bug. ***
*** This bug has been marked as a duplicate of bug 60102 ***