jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1202764 - in /jackrabbit/branches/2.2: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/...
Date Wed, 16 Nov 2011 16:18:33 GMT
Author: jukka
Date: Wed Nov 16 16:18:33 2011
New Revision: 1202764

URL: http://svn.apache.org/viewvc?rev=1202764&view=rev
Log:
2.2: Merged revision 1077927 (JCR-2903)

Added:
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueInputStreamTest.java
      - copied unchanged from r1077927, jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueInputStreamTest.java
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/util/InputStreamWrapper.java
      - copied unchanged from r1077927, jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/util/InputStreamWrapper.java
Modified:
    jackrabbit/branches/2.2/   (props changed)
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
    jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
    jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractWorkspace.java
    jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/AbstractValueFactory.java
    jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientSession.java
    jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ShareableNodeTest.java
    jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ValueFactoryTest.java
    jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
    jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFactoryQImpl.java

Propchange: jackrabbit/branches/2.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Nov 16 16:18:33 2011
@@ -3,4 +3,4 @@
 /jackrabbit/sandbox/JCR-1456:774917-886178
 /jackrabbit/sandbox/JCR-2170:812417-816332
 /jackrabbit/sandbox/tripod-JCR-2209:795441-795863
-/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1043893,1043897,1044239,1044312,1044451,1044613,1049473,1049491,1049514,1049518,1049520,1049859,1049870,1049874,1049878,1049880,1049883,1049889,1049891,1049894-1049895,1049899-1049901,1049909-1049911,1049915-1049916,1049919,1049923,1049925,1049931,1049936,1049939,1050212,1050298,1050346,1050551,1055068,1055070-1055071,1055116-1055117,1055127,1055134,1055164,1055498,1060431,1060434,1060753,1063756,1064213,1064670,1065599,1065622,1066059,1066071,1066794,1069831,1071562,1071573,1071680,1072087,1074140,1077970,1079314,1079317,1080186,1080540,1087304,1088991,1089032,1089053,1089436,1092106,1092117,1092683,1097363,1097513-1097514,1098963-1098964,1099033,1099172,1100242,110
 0286,1101046,1102262,1102268-1102270,1102299,1102601,1104027,1128175,1129206,1130192,1130228,1132993,1136353,1136360,1138511,1141141,1141717,1143396,1143738,1144332,1144338,1144695,1152258,1155431,1157175,1165609,1173196,1174822,1174887,1175988,1176423,1176465,1176515,1176546,1177249,1177340,1178251,1178892,1179548,1180922,1181712,1182281,1182667,1182929,1183409,1185691,1186285,1186802,1187344,1188541,1188590,1198827
+/jackrabbit/trunk:1038201,1038203,1038205,1038657,1039064,1039347,1039408,1039422-1039423,1039888,1039946,1040033,1040090,1040459,1040601,1040606,1040661,1040958,1041379,1041439,1041761,1042643,1042647,1042978-1042982,1043084-1043086,1043088,1043343,1043357-1043358,1043430,1043554,1043616,1043618,1043637,1043656,1043893,1043897,1044239,1044312,1044451,1044613,1049473,1049491,1049514,1049518,1049520,1049859,1049870,1049874,1049878,1049880,1049883,1049889,1049891,1049894-1049895,1049899-1049901,1049909-1049911,1049915-1049916,1049919,1049923,1049925,1049931,1049936,1049939,1050212,1050298,1050346,1050551,1055068,1055070-1055071,1055116-1055117,1055127,1055134,1055164,1055498,1060431,1060434,1060753,1063756,1064213,1064670,1065599,1065622,1066059,1066071,1066794,1069831,1071562,1071573,1071680,1072087,1074140,1077927,1077970,1079314,1079317,1080186,1080540,1087304,1088991,1089032,1089053,1089436,1092106,1092117,1092683,1097363,1097513-1097514,1098963-1098964,1099033,1099172,110
 0242,1100286,1101046,1102262,1102268-1102270,1102299,1102601,1104027,1128175,1129206,1130192,1130228,1132993,1136353,1136360,1138511,1141141,1141717,1143396,1143738,1144332,1144338,1144695,1152258,1155431,1157175,1165609,1173196,1174822,1174887,1175988,1176423,1176465,1176515,1176546,1177249,1177340,1178251,1178892,1179548,1180922,1181712,1182281,1182667,1182929,1183409,1185691,1186285,1186802,1187344,1188541,1188590,1198827

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/ValueFactoryImpl.java
Wed Nov 16 16:18:33 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.value;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.core.data.DataIdentifier;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
@@ -79,6 +80,9 @@ public class ValueFactoryImpl extends Va
             }
         } catch (IOException e) {
             throw new RepositoryException(e);
+        } finally {
+            // JCR-2903
+            IOUtils.closeQuietly(stream);
         }
     }
 
@@ -116,6 +120,9 @@ public class ValueFactoryImpl extends Va
             throw new RuntimeException(ex);
         } catch (RepositoryException ex) {
             throw new RuntimeException(ex);
+        } finally {
+            // JCR-2903
+            IOUtils.closeQuietly(value);
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractSession.java
Wed Nov 16 16:18:33 2011
@@ -351,6 +351,11 @@ public abstract class AbstractSession im
             } else {
                 throw new InvalidSerializedDataException("XML parse error", e);
             }
+        } finally {
+            // JCR-2903
+            if (in != null) {
+                try { in.close(); } catch (IOException ignore) {}
+            }
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractWorkspace.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractWorkspace.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractWorkspace.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/AbstractWorkspace.java
Wed Nov 16 16:18:33 2011
@@ -61,6 +61,11 @@ public abstract class AbstractWorkspace 
             } else {
                 throw new InvalidSerializedDataException("XML parse error", e);
             }
+        } finally {
+            // JCR-2903
+            if (in != null) {
+                try { in.close(); } catch (IOException ignore) {}
+            }
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/AbstractValueFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/AbstractValueFactory.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/AbstractValueFactory.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/AbstractValueFactory.java
Wed Nov 16 16:18:33 2011
@@ -88,7 +88,12 @@ public abstract class AbstractValueFacto
      * {@inheritDoc}
      */
     public Value createValue(InputStream value) {
-        return new BinaryValue(value);
+        try {
+            return new BinaryValue(value);
+        } finally {
+            // JCR-2903
+            try { value.close(); } catch (IOException ignore) {}
+        }
     }
 
     /**
@@ -171,6 +176,9 @@ public abstract class AbstractValueFacto
             return new BinaryImpl(stream);
         } catch (IOException e) {
             throw new RepositoryException("failed to create Binary instance", e);
+        } finally {
+            // JCR-2903
+            try { stream.close(); } catch (IOException ignore) {}
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientSession.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientSession.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientSession.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientSession.java
Wed Nov 16 16:18:33 2011
@@ -333,6 +333,9 @@ public class ClientSession extends Clien
             remote.importXML(path, buffer.toByteArray(), mode);
         } catch (RemoteException ex) {
             throw new RemoteRepositoryException(ex);
+        } finally {
+            // JCR-2903
+            try { xml.close(); } catch (IOException ignore) {}
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-rmi/src/main/java/org/apache/jackrabbit/rmi/client/ClientWorkspace.java
Wed Nov 16 16:18:33 2011
@@ -231,6 +231,9 @@ public class ClientWorkspace extends Cli
             remote.importXML(path, buffer.toByteArray(), uuidBehaviour);
         } catch (RemoteException ex) {
             throw new RemoteRepositoryException(ex);
+        } finally {
+            // JCR-2903
+            try { xml.close(); } catch (IOException ignore) {}
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/AbstractImportXmlTest.java
Wed Nov 16 16:18:33 2011
@@ -242,7 +242,7 @@ abstract class AbstractImportXmlTest ext
                 session.save();
             }
         } finally {
-            bin.close();
+            try { bin.close(); } catch (IOException ignore) {}
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
Wed Nov 16 16:18:33 2011
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.api.util.InputStreamWrapper;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -145,7 +146,7 @@ public class SerializationTest extends A
         } catch (VersionException e) {
             // success
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 
@@ -160,7 +161,7 @@ public class SerializationTest extends A
         } catch (VersionException e) {
             // success
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 
@@ -216,7 +217,7 @@ public class SerializationTest extends A
             } catch (LockException e) {
                 // success
             } finally {
-                in.close();
+                try { in.close(); } catch (IOException ignore) {}
             }
         } else {
             log.println("Locking not supported.");
@@ -353,7 +354,7 @@ public class SerializationTest extends A
         } catch (PathNotFoundException e) {
             // success
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 
@@ -372,7 +373,7 @@ public class SerializationTest extends A
         } catch (PathNotFoundException e) {
             // success
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 
@@ -416,7 +417,7 @@ public class SerializationTest extends A
                 }
             }
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 
@@ -477,7 +478,7 @@ public class SerializationTest extends A
                 }
             }
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 
@@ -510,7 +511,7 @@ public class SerializationTest extends A
             session.importXML(treeComparator.targetFolder, in,
                     ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
 
         // after logout/login, no nodes are in the session
@@ -533,7 +534,7 @@ public class SerializationTest extends A
             exportRepository(SAVEBINARY, RECURSE);
             doImportNoSave(treeComparator.targetFolder, in, CONTENTHANDLER);
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
 
         // after logout/login, no nodes are in the session
@@ -545,11 +546,33 @@ public class SerializationTest extends A
         treeComparator.compare(treeComparator.CHECK_EMPTY);
     }
 
+//----------------< tests input stream handling contract >----------------------
+
+    /**
+     * Tests whether <code>Session.importXML</code> and <code>Workspace.importXML</code>
+     * obey the stream handling contract.
+     */
+    public void testStreamHandling() throws RepositoryException, IOException {
+        exportRepository(SAVEBINARY, RECURSE);
+
+        InputStreamWrapper in = new InputStreamWrapper(new FileInputStream(file));
+        session.importXML(treeComparator.targetFolder, in,
+                ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+        assertTrue("Session.importXML(..., InputStream, ...) is expected to close the passed
input stream", in.isClosed());
+        session.refresh(false);
+
+        in = new InputStreamWrapper(new FileInputStream(file));
+        workspace.importXML(treeComparator.targetFolder, in,
+                ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+        assertTrue("Workspace.importXML(..., InputStream, ...) is expected to close the passed
input stream", in.isClosed());
+    }
+
+
 //----------------< import test helper >--------------------------------------------------------
     /**
      * Helper method which imports the given FileInputStream using Workspace or Session
-     * and via the methods importXML respective getImportContentHandler. Teh target node
of the
-     * import is specified with its absolut path.
+     * and via the methods importXML respective getImportContentHandler. The target node
of the
+     * import is specified with its absolute path.
      *
      * @param absPath
      * @param in
@@ -729,7 +752,7 @@ public class SerializationTest extends A
         } catch (SAXException e) {
             fail("Error while parsing the imported repository: " + e);
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java
Wed Nov 16 16:18:33 2011
@@ -270,9 +270,7 @@ public class SetPropertyConstraintViolat
         } catch (ConstraintViolationException e) {
             // success
         } finally {
-            try {
-                in.close();
-            } catch (IOException ignore) {}
+            try { in.close(); } catch (IOException ignore) {}
         }
 
         // test of signature setProperty(String name, Value value)

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java
Wed Nov 16 16:18:33 2011
@@ -18,10 +18,12 @@ package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.api.util.InputStreamWrapper;
 
 import javax.jcr.Node;
 import javax.jcr.Property;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.ByteArrayInputStream;
 
@@ -74,8 +76,8 @@ public class SetPropertyInputStreamTest 
             assertTrue("Setting property with Node.setProperty(String, InputStream) and Session.save()
not working",
                     compareInputStreams(is1, in));
         } finally {
-            in.close();
-        }
+            try { in.close(); } catch (IOException ignore) {}
+         }
     }
 
     /**
@@ -93,8 +95,8 @@ public class SetPropertyInputStreamTest 
             assertTrue("Modifying property with Node.setProperty(String, InputStream) and
Session.save() not working",
                     compareInputStreams(is2, in));
         } finally {
-            in.close();
-        }
+            try { in.close(); } catch (IOException ignore) {}
+         }
     }
 
     /**
@@ -110,7 +112,7 @@ public class SetPropertyInputStreamTest 
             assertTrue("Setting property with Node.setProperty(String, InputStream) and parentNode.save()
not working",
                     compareInputStreams(is1, in));
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 
@@ -129,8 +131,8 @@ public class SetPropertyInputStreamTest 
             assertTrue("Modifying property with Node.setProperty(String, InputStream) and
parentNode.save() not working",
                     compareInputStreams(is2, in));
         } finally {
-            in.close();
-        }
+            try { in.close(); } catch (IOException ignore) {}
+         }
     }
 
     /**
@@ -174,6 +176,16 @@ public class SetPropertyInputStreamTest 
     }
 
     /**
+     * Tests whether the passed input stream is closed.
+     * @throws Exception
+     */
+    public void testInputStreamClosed() throws Exception {
+        InputStreamWrapper in = new InputStreamWrapper(new ByteArrayInputStream(bytes1));
+        testNode.setProperty(propertyName1, in);
+        assertTrue("Node.setProperty(..., InputStream) is expected to close the passed input
stream", in.isClosed());
+    }
+
+    /**
      * helper function: InputStream comparison
      */
     private boolean compareInputStreams(InputStream f1, InputStream f2) {

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
Wed Nov 16 16:18:33 2011
@@ -110,7 +110,7 @@ public class SetValueBinaryTest extends 
         try {
             compareStream(data, in);
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 
@@ -127,7 +127,7 @@ public class SetValueBinaryTest extends 
             try {
                 compareStream(data, in);
             } finally {
-                in.close();
+                try { in.close(); } catch (IOException ignore) {}
             }
         } finally {
             bin.dispose();
@@ -144,13 +144,13 @@ public class SetValueBinaryTest extends 
             property1.setValue(in);
             node.save();
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
         in = property1.getValue().getStream();
         try {
             compareStream(data, in);
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
     }
 
@@ -168,7 +168,7 @@ public class SetValueBinaryTest extends 
             try {
                 compareStream(data, in);
             } finally {
-                in.close();
+                try { in.close(); } catch (IOException ignore) {}
             }
         } finally {
             bin.dispose();

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java
Wed Nov 16 16:18:33 2011
@@ -102,9 +102,7 @@ public class SetValueConstraintViolation
         } catch (ConstraintViolationException e) {
             // success
         } finally {
-            try {
-                in.close();
-            } catch (IOException ignore) {}
+            try { in.close(); } catch (IOException ignore) {}
         }
 
         // test of signature setValue(Value value)

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ShareableNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ShareableNodeTest.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ShareableNodeTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ShareableNodeTest.java
Wed Nov 16 16:18:33 2011
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.test.api;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
@@ -675,7 +676,7 @@ public class ShareableNodeTest extends A
             workspace.importXML(testRootNode.getPath(), in,
                     ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
 
         // verify shared set consists of two nodes
@@ -728,7 +729,7 @@ public class ShareableNodeTest extends A
         try {
             workspace.importXML(a3.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
 
         // verify there's another element in the shared set
@@ -785,7 +786,7 @@ public class ShareableNodeTest extends A
         try {
             workspace.importXML(a3.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
 
         // verify there's another element in the shared set
@@ -843,7 +844,7 @@ public class ShareableNodeTest extends A
             session.importXML(a3.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
             session.save();
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
 
         // verify there's another element in the shared set
@@ -901,7 +902,7 @@ public class ShareableNodeTest extends A
             session.importXML(a3.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
             session.save();
         } finally {
-            in.close();
+            try { in.close(); } catch (IOException ignore) {}
         }
 
         // verify there's another element in the shared set

Modified: jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ValueFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ValueFactoryTest.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ValueFactoryTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ValueFactoryTest.java
Wed Nov 16 16:18:33 2011
@@ -18,7 +18,9 @@ package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
+import org.apache.jackrabbit.test.api.util.InputStreamWrapper;
 
+import javax.jcr.Binary;
 import javax.jcr.Session;
 import javax.jcr.ValueFactory;
 import javax.jcr.Node;
@@ -319,4 +321,21 @@ public class ValueFactoryTest extends Ab
         }
 
     }
+
+    /**
+     * Tests whether a passed <code>InputStream</code> is closed
+     * by the implementation.
+     *
+     * @throws RepositoryException
+     */
+    public void testInputStream() throws RepositoryException {
+        InputStreamWrapper in = new InputStreamWrapper(new ByteArrayInputStream(binaryValue));
+        valueFactory.createValue(in);
+        assertTrue("ValueFactory.createValue(InputStream) is expected to close the passed
input stream", in.isClosed());
+
+        in = new InputStreamWrapper(new ByteArrayInputStream(binaryValue));
+        Binary bin = valueFactory.createBinary(in);
+        assertTrue("ValueFactory.createBinary(InputStream) is expected to close the passed
input stream", in.isClosed());
+        bin.dispose();
+    }
 }

Modified: jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
Wed Nov 16 16:18:33 2011
@@ -51,6 +51,7 @@ import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.commons.collections.map.ReferenceMap;
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.commons.AbstractSession;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.jcr2spi.config.RepositoryConfig;
@@ -409,6 +410,9 @@ public class SessionImpl extends Abstrac
             }
         } catch (ParserConfigurationException e) {
             throw new RepositoryException("SAX parser configuration error", e);
+        } finally {
+            // JCR-2903
+            IOUtils.closeQuietly(in);
         }
     }
 

Modified: jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
Wed Nov 16 16:18:33 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.jcr2spi;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.jcr2spi.config.CacheBehaviour;
 import org.apache.jackrabbit.jcr2spi.config.RepositoryConfig;
 import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManager;
@@ -339,8 +340,13 @@ public class WorkspaceImpl implements Wo
         int options = ItemStateValidator.CHECK_ACCESS | ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_VERSIONING;
         getValidator().checkIsWritable(parentState, options);
 
-        // run the import
-        wspManager.execute(WorkspaceImport.create(parentState, in, uuidBehavior));
+        try {
+            // run the import
+            wspManager.execute(WorkspaceImport.create(parentState, in, uuidBehavior));
+        } finally {
+            // JCR-2903
+            IOUtils.closeQuietly(in);
+        }
     }
 
     /**

Modified: jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFactoryQImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFactoryQImpl.java?rev=1202764&r1=1202763&r2=1202764&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFactoryQImpl.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFactoryQImpl.java
Wed Nov 16 16:18:33 2011
@@ -30,6 +30,7 @@ import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.ValueFormatException;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
@@ -158,6 +159,9 @@ public class ValueFactoryQImpl implement
             throw new RuntimeException(ex);
         } catch (RepositoryException ex) {
             throw new RuntimeException(ex);
+        } finally {
+            // JCR-2903
+            IOUtils.closeQuietly(value);
         }
     }
 
@@ -208,6 +212,9 @@ public class ValueFactoryQImpl implement
             throw new RuntimeException(ex);
         } catch (RepositoryException ex) {
             throw new RuntimeException(ex);
+        } finally {
+            // JCR-2903
+            IOUtils.closeQuietly(stream);
         }
     }
 



Mime
View raw message