summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2018-09-27 19:06:06 +0000
committerPJ Fanning <fanningpj@apache.org>2018-09-27 19:06:06 +0000
commit44e86832f299bde657135d148fe55af7aeb1cd45 (patch)
tree6481136173a3159b74b0af9737009a52701e4d21
parent43c57c26c26d85a0e083d40b92e98a0f5efb34a2 (diff)
downloadpoi-44e86832f299bde657135d148fe55af7aeb1cd45.tar.gz
poi-44e86832f299bde657135d148fe55af7aeb1cd45.zip
[bug-62768] synchronize OPCPackage#close()
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1842142 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java36
1 files changed, 14 insertions, 22 deletions
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
index 5d9c7b9ae4..949ec69520 100644
--- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
+++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
@@ -28,7 +28,6 @@ import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -420,7 +419,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* If an IO exception occur during the saving process.
*/
@Override
- public void close() throws IOException {
+ public synchronized void close() throws IOException {
if (this.packageAccess == PackageAccess.READ) {
logger.log(POILogger.WARN,
"The close() method is intended to SAVE a package. This package is open in READ ONLY mode, use the revert() method instead !");
@@ -434,27 +433,20 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
return;
}
- // Save the content
- ReentrantReadWriteLock l = new ReentrantReadWriteLock();
- try {
- l.writeLock().lock();
- if (this.originalPackagePath != null
- && !this.originalPackagePath.trim().isEmpty()) {
- File targetFile = new File(this.originalPackagePath);
- if (!targetFile.exists()
- || !(this.originalPackagePath
- .equalsIgnoreCase(targetFile.getAbsolutePath()))) {
- // Case of a package created from scratch
- save(targetFile);
- } else {
- closeImpl();
- }
- } else if (this.output != null) {
- save(this.output);
- output.close();
+ if (this.originalPackagePath != null
+ && !this.originalPackagePath.trim().isEmpty()) {
+ File targetFile = new File(this.originalPackagePath);
+ if (!targetFile.exists()
+ || !(this.originalPackagePath
+ .equalsIgnoreCase(targetFile.getAbsolutePath()))) {
+ // Case of a package created from scratch
+ save(targetFile);
+ } else {
+ closeImpl();
}
- } finally {
- l.writeLock().unlock();
+ } else if (this.output != null) {
+ save(this.output);
+ output.close();
}
// Clear