Bug 59158 - OpenXML4JRuntimeException: Rule M2.4 exception
Summary: OpenXML4JRuntimeException: Rule M2.4 exception
Status: RESOLVED DUPLICATE of bug 60102
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.13-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
: 59159 61297 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-03-10 00:57 UTC by Stefan
Modified: 2018-02-10 14:50 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan 2016-03-10 00:57:35 UTC
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();
        }
Comment 1 Dominik Stadler 2016-03-11 22:32:39 UTC
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.
Comment 2 Dominik Stadler 2016-03-11 22:34:02 UTC
Oops, sorry, just saw the additional part in the description.
Comment 3 Dominik Stadler 2016-03-11 22:36:21 UTC
*** Bug 59159 has been marked as a duplicate of this bug. ***
Comment 4 Dominik Stadler 2016-03-28 20:49:56 UTC
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.
Comment 5 Javen O'Neal 2016-10-29 21:08:59 UTC
> 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.
Comment 6 Javen O'Neal 2017-07-14 00:12:31 UTC
*** Bug 61297 has been marked as a duplicate of this bug. ***
Comment 7 Alain Fagot Bearez 2018-02-10 14:50:27 UTC

*** This bug has been marked as a duplicate of bug 60102 ***