Bug 62629 - Reaching a Rule M2.4 exception when trying to merge two files
Summary: Reaching a Rule M2.4 exception when trying to merge two files
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.17-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
: 58917 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-08-16 10:32 UTC by Lucas
Modified: 2019-03-10 20:25 UTC (History)
1 user (show)



Attachments
Stacktrace (1.16 KB, text/plain)
2018-08-16 10:32 UTC, Lucas
Details
The java class used for merging the 2 workbook (20.28 KB, text/plain)
2018-08-16 10:34 UTC, Lucas
Details
The sheet to merge to trigger error (21.32 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2018-08-16 10:35 UTC, Lucas
Details
The target workbook to trigger the error (32.24 KB, application/vnd.ms-excel.sheet.macroEnabled.12)
2018-08-16 10:35 UTC, Lucas
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lucas 2018-08-16 10:32:44 UTC
Created attachment 36093 [details]
Stacktrace

Hello,

I have a piece of code that I use to merge one excel sheet into a target Workbook. The code used is pretty much coming from the following resource: www.coderanch.com/t/420958/open-source/Copying-sheet-excel-file-excel.

While merging, an error is thrown by POI ContentTypeManage at:

if (this.container != null && this.container.getPart(partName) != null) {
			throw new OpenXML4JRuntimeException(
					"Rule M2.4 exception : this error should NEVER happen! If you can provide the triggering file, then please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach the file that triggers it, thanks!");
		}

I tried to downsize the excel files used in my case, and I end up with the files attached:

- targetWorkbook.xlsm which will receive the copy of the sheet. This workbook contains a button (no macro attached anymore) and a picture.
- sheetToMerge.xlsx which contains the data to be copied in the target Workbook. This sheet at the time being contains only one picture.

Now, the code will work under any of the following conditions:

- Remove the button from the targetWorkbook
- Remove the image from the targetWorkbook
- Remove the image from the sheetToMerge

I have dug a bit in the code, and also checked the [Content_Types].xml files for all these workbooks, with no luck till now.

I attach the stacktrace, the code, and 2 files triggering the error.

PS: I am aware of the bug 62522; but I have reduced the files and the test case used to trigger the bug, and i believe that the premise of the bug opening was wrong. This bug is not solved if, i/o a jpg and a jpeg, I have two jpg, or two jpeg. Plus, the error is not triggered if the button is removed, but still we have both jpg and jpeg.
Comment 1 Lucas 2018-08-16 10:34:22 UTC
Created attachment 36094 [details]
The java class used for merging the 2 workbook
Comment 2 Lucas 2018-08-16 10:35:10 UTC
Created attachment 36095 [details]
The sheet to merge to trigger error
Comment 3 Lucas 2018-08-16 10:35:51 UTC
Created attachment 36096 [details]
The target workbook to trigger the error
Comment 4 Dominik Stadler 2018-12-27 20:52:34 UTC
The problem is in the two source files, one has default content-type for extension "jpg", the other for "jpeg". 

It seems the application which produces these files is not creating fully standard-conforming files.

one file:
<Default Extension="jpeg" ContentType="image/jpeg"/>

other file:
<Default Extension="jpg" ContentType="image/jpeg"/>

We now gracefully handle such situations with r1849814, but such files might cause other issues in LibreOffice or Excel.
Comment 5 Dominik Stadler 2019-03-10 20:25:40 UTC
*** Bug 58917 has been marked as a duplicate of this bug. ***