Bug 567798 - Saving Excel file twice corrupts the document
Summary: Saving Excel file twice corrupts the document
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.19   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-12 03:03 EDT by Flavio Donze CLA
Modified: 2021-05-19 11:13 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Flavio Donze CLA 2020-10-12 03:03:16 EDT
Steps to reproduce:

- Download latest Eclipse IDE (2020-09)
- Start Eclipse and create an empty project
- copy new empty excel file to project
- open excel file
- make a change and save (WORKS)
- make another change and save (FAILS, editor stays dirty and changes are not stored)

java.runtime.version=14.0.2+12
eclipse.buildId=4.17.0.I20200902-1800
Microsoft Excel 2016 MSO
Comment 1 Flavio Donze CLA 2021-05-18 08:22:27 EDT
This issue remains in the current Eclipse 2021-03 (4.19.0).
Comment 2 Flavio Donze CLA 2021-05-18 08:42:01 EDT
The behavior is worse than originally stated, the editor not only stays dirty after the second save but corrupts the document.

Steps to reproduce: 
- Download latest Eclipse IDE (2021-03) -> https://www.eclipse.org/downloads/packages/release/2021-03/r/eclipse-ide-java-developers
- Start Eclipse and create an empty project
- copy an excel file with content to the project (11’809 bytes)
- open excel file
- make a change and save (WORKS) (11’448  bytes)
- make another change and save (FAILS, editor stays dirty and file is now corrupt) (3’399  bytes)

Saving only once doesn't corrupt the document:
- open - modify - save - close
- open - modify - save - close
Comment 3 Flavio Donze CLA 2021-05-18 09:00:33 EDT
Also issue remains in current milestone release:
Version: 2021-06 (4.20)
Build id: I20210407-1800
Comment 4 Flavio Donze CLA 2021-05-19 10:32:31 EDT
Just came across this interesting code:

OleClientSite.java
public boolean save(File file, boolean includeOleInfo) {
  /*
  * Bug in Office 2007. Saving Office 2007 documents to compound file storage object
  * causes the output file to be corrupted. The fix is to detect Office 2007 documents
  * using the program ID and save only the content of the 'Package' stream.
  */
  if (isOffice2007(false)) {
  	return saveOffice2007(file);
  }
  if (includeOleInfo)
  	return saveToStorageFile(file);
  return saveToTraditionalFile(file);
}

In my case isOffice2007() returns "true" even though using Office 2016. Which then ignores the includeOleInfo parameter.
Comment 5 Flavio Donze CLA 2021-05-19 11:13:20 EDT
This hack solved the issue in my case, the root of the problems seems to be the saveOffice2007().

// call private saveToStorageFile() to prevent OleClientSite.saveOffice2007() being called
Method method = OleClientSite.class.getDeclaredMethod("saveToStorageFile", File.class);
method.setAccessible(true);
method.invoke(clientSite, file);