Bug 62985 - Writing to new file saves also changes in source file
Summary: Writing to new file saves also changes in source file
Status: RESOLVED DUPLICATE of bug 59287
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: 4.0.0-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-06 07:52 UTC by daniela.loew
Modified: 2018-12-06 07:59 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description daniela.loew 2018-12-06 07:52:09 UTC
If I open an existing Excel document, do some changes and save it with a new file name, the changes are saved in both files. Saving it with the same file name as the source file leads to the following exception:

Exception in thread "main" org.apache.poi.ooxml.POIXMLException: java.io.EOFException: Unexpected end of ZLIB input stream
	at org.apache.poi.ooxml.POIXMLDocument.getProperties(POIXMLDocument.java:147)
	at org.apache.poi.ooxml.POIXMLDocument.write(POIXMLDocument.java:240)
	at de.giz.meb.POIProof.main(POIProof.java:28)
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
	at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:240)
	at org.apache.commons.compress.archivers.zip.InflaterInputStreamWithStatistics.fill(InflaterInputStreamWithStatistics.java:52)
	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
	at org.apache.commons.compress.archivers.zip.InflaterInputStreamWithStatistics.read(InflaterInputStreamWithStatistics.java:67)
	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:122)
	at org.apache.commons.compress.archivers.zip.InflaterInputStreamWithStatistics.read(InflaterInputStreamWithStatistics.java:58)
	at java.io.FilterInputStream.read(FilterInputStream.java:83)
	at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.read(ZipArchiveThresholdInputStream.java:69)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2890)
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:674)
	at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:148)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:806)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
	at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3414)
	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1272)
	at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1259)
	at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
	at org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument$Factory.parse(Unknown Source)
	at org.apache.poi.ooxml.POIXMLProperties.<init>(POIXMLProperties.java:81)
	at org.apache.poi.ooxml.POIXMLDocument.getProperties(POIXMLDocument.java:145)
	... 2 more


You can test it with the following code:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

public class POIProof {

	public static void main(String[] args) {
		Workbook w;
		try {
			// open existing file
			w = WorkbookFactory.create(new File("C:\\dev\\MyExcel.xlsx"));
			Sheet s = w.getSheetAt(0);
			Row r = s.getRow(0);
			Cell c = r.createCell(1);
			c.setCellValue("Easy Test");
			// write to new file
			FileOutputStream out = new FileOutputStream("C:\\dev\\MyExcel_mod.xlsx");
			w.write(out);
			w.close();			
		} catch (EncryptedDocumentException | IOException e) {
			//TODO
		} 
		
		
	}

}

We tested that with Version 4.0.0-FINAL and 4.0.1.

Using XSSFWorkbook instead worked fine.
Comment 1 Andreas Beeker 2018-12-06 07:59:25 UTC

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