Skip to content

Commit 1ef0ab9

Browse files
author
Horia Chiorean
committed
Merge pull request #1547 from hchiorean/MODE-2589
MODE-2589 Fixes the handling of empty binaries by the DatabaseBinaryStore in the case of Oracle
2 parents 1068e9b + a47dbfc commit 1ef0ab9

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

modeshape-jcr/src/main/java/org/modeshape/jcr/value/binary/Database.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.modeshape.jcr.value.binary;
1717

18+
import java.io.ByteArrayInputStream;
1819
import java.io.IOException;
1920
import java.io.InputStream;
2021
import java.sql.Connection;
@@ -465,7 +466,8 @@ protected DatabaseBinaryStream( Connection connection,
465466
InputStream jdbcBinaryStream ) {
466467
this.connection = connection;
467468
this.statement = statement;
468-
this.jdbcBinaryStream = jdbcBinaryStream;
469+
// some drivers (notably Oracle) can return a null stream if the stored binary is empty (i.e. has 0 bytes)
470+
this.jdbcBinaryStream = jdbcBinaryStream != null ? jdbcBinaryStream : new ByteArrayInputStream(new byte[0]);
469471
}
470472

471473
@Override

web/modeshape-web-jcr-webdav/src/test/java/org/modeshape/web/jcr/webdav/ModeShapeWebdavStoreTest.java

+37-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.mockito.Mock;
3434
import static org.mockito.Mockito.when;
3535
import org.mockito.MockitoAnnotations;
36+
import org.modeshape.common.FixFor;
3637
import org.modeshape.common.util.IoUtil;
3738
import org.modeshape.jcr.api.RepositoryFactory;
3839
import org.modeshape.web.jcr.ModeShapeJcrDeployer;
@@ -135,7 +136,7 @@ public void shouldNotCommitNullTransaction() throws Exception {
135136

136137
private void compareChildrenWithSession( String[] children,
137138
String path ) throws Exception {
138-
List<String> sessChildren = new LinkedList<String>();
139+
List<String> sessChildren = new LinkedList<>();
139140
Node node = (Node)session.getItem(path);
140141
for (NodeIterator iter = node.getNodes(); iter.hasNext(); ) {
141142
sessChildren.add(iter.nextNode().getName());
@@ -253,4 +254,39 @@ public void shouldSimulateAddingFileThroughWebdav() throws Exception {
253254
assertThat(ob, is(notNullValue()));
254255
}
255256

257+
@Test
258+
@FixFor( "MODE-2589" )
259+
public void shouldSimulateAddingAndCopyingZeroLengthFileThroughWebdav() throws Exception {
260+
final String testString = "";
261+
final String sourceUri = TEST_ROOT_PATH + "/TestFile.rtf";
262+
final String destinationUri = TEST_ROOT_PATH + "/CopyOfTestFile.rtf";
263+
264+
when(request.getPathInfo()).thenReturn("");
265+
store.getStoredObject(tx, "");
266+
267+
when(request.getPathInfo()).thenReturn(sourceUri);
268+
store.getStoredObject(tx, sourceUri);
269+
270+
when(request.getPathInfo()).thenReturn("/"); // will ask for parent during resolution ...
271+
store.createResource(tx, sourceUri);
272+
273+
when(request.getPathInfo()).thenReturn(sourceUri);
274+
long length = store.setResourceContent(tx, sourceUri, new ByteArrayInputStream(testString.getBytes()), "text/plain",
275+
"UTF-8");
276+
277+
assertThat((int)length, is(testString.getBytes().length));
278+
279+
StoredObject ob = store.getStoredObject(tx, sourceUri);
280+
assertThat(ob, is(notNullValue()));
281+
282+
when(request.getPathInfo()).thenReturn("/"); // will ask for parent during resolution ...
283+
store.createResource(tx, destinationUri);
284+
285+
when(request.getPathInfo()).thenReturn(destinationUri);
286+
length = store.setResourceContent(tx, destinationUri, store.getResourceContent(tx, sourceUri), "text/plain", "UTF-8");
287+
288+
assertThat((int)length, is(testString.getBytes().length));
289+
ob = store.getStoredObject(tx, destinationUri);
290+
assertThat(ob, is(notNullValue()));
291+
}
256292
}

0 commit comments

Comments
 (0)