You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2023/05/15 17:57:52 UTC
[jackrabbit-oak] branch trunk updated: OAK-10241: NPE while trying to get the BinaryDownload URI
This is an automated email from the ASF dual-hosted git repository.
mreutegg pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push:
new 2ca949bdf4 OAK-10241: NPE while trying to get the BinaryDownload URI
new 45d41e4a43 Merge pull request #939 from mreutegg/OAK-10241
2ca949bdf4 is described below
commit 2ca949bdf408744d72ef6436e1d33adcf0523dea
Author: Marcel Reutegger <ma...@gmail.com>
AuthorDate: Mon May 15 11:55:30 2023 +0200
OAK-10241: NPE while trying to get the BinaryDownload URI
Add test and implement fix
---
.../oak/plugins/value/jcr/BinaryImpl.java | 10 +++---
.../oak/plugins/value/jcr/BinaryImplTest.java | 38 ++++++++++++++++++++++
2 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/value/jcr/BinaryImpl.java b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/value/jcr/BinaryImpl.java
index 99d4e7238e..ac36f7f6a6 100644
--- a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/value/jcr/BinaryImpl.java
+++ b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/value/jcr/BinaryImpl.java
@@ -93,18 +93,20 @@ class BinaryImpl implements ReferenceBinary, BinaryDownload {
@Override
public URI getURI(@NotNull BinaryDownloadOptions downloadOptions)
throws RepositoryException {
- if (value.getBlob().isInlined()) {
- // Binary is inlined, we cannot return a URI for it
+ ValueImpl v = getBinaryValue();
+ if (v == null || v.getBlob().isInlined()) {
+ // property is not a binary, or it is inlined
+ // we cannot return a URI for it
return null;
}
// ValueFactoryImpl.getBlobId() will only return a blobId for a BinaryImpl, which
// a client cannot spoof, so we know that the id in question is valid and can be
// trusted, so we can safely give out a URI to the binary for downloading.
- Blob blob = getBinaryValue().getBlob();
+ Blob blob = v.getBlob();
String blobId = blob.getContentIdentity();
if (null != blobId) {
- return value.getDownloadURI(blob, downloadOptions);
+ return v.getDownloadURI(blob, downloadOptions);
}
return null;
}
diff --git a/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/plugins/value/jcr/BinaryImplTest.java b/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/plugins/value/jcr/BinaryImplTest.java
new file mode 100644
index 0000000000..7b628b8443
--- /dev/null
+++ b/oak-store-spi/src/test/java/org/apache/jackrabbit/oak/plugins/value/jcr/BinaryImplTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.value.jcr;
+
+import org.apache.jackrabbit.api.binary.BinaryDownloadOptions;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.plugins.memory.StringPropertyState;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNull;
+
+public class BinaryImplTest {
+
+ @Test // OAK-10241
+ public void getURIFromNonBinaryType() throws Exception {
+ NamePathMapper mapper = new NamePathMapper.Default();
+ PartialValueFactory vf = new PartialValueFactory(mapper);
+ PropertyState p = new StringPropertyState("name", "value");
+ ValueImpl value = new ValueImpl(p, mapper, vf.getBlobAccessProvider());
+ BinaryImpl binary = new BinaryImpl(value);
+ assertNull(binary.getURI(BinaryDownloadOptions.DEFAULT));
+ }
+}