Author: fanningpj
Date: Thu Sep 27 19:06:06 2018
New Revision: 1842142

URL: http://svn.apache.org/viewvc?rev=1842142&view=rev
Log:
[bug-62768] synchronize OPCPackage#close()

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java?rev=1842142&r1=1842141&r2=1842142&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java Thu 
Sep 27 19:06:06 2018
@@ -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 impleme
         *             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 impleme
                    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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to