SLING-11465 : NPE in JcrPropertyMapCacheEntry when converting from InputStream value to Number
diff --git a/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java b/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java
index dcc2e02..d5f1efd 100644
--- a/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java
+++ b/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java
@@ -299,6 +299,11 @@
// any number: length of binary
} else if (Number.class.isAssignableFrom(type)) {
+ // avoid NPE if this instance has not been created from a property (see SLING-11465)
+ if (property == null) {
+ return null;
+ }
+
if (index == -1) {
value = Long.valueOf(this.property.getLength());
} else {
diff --git a/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java b/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java
index 53d2d44..d53c08d 100644
--- a/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java
+++ b/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java
@@ -135,7 +135,7 @@
JcrPropertyMapCacheEntry entry = new JcrPropertyMapCacheEntry(in, node);
Long result = entry.convertToType(Long.class, node, null);
- assertEquals(Long.valueOf(2), result);
+ assertNull(result);
verifyZeroInteractions(node);
}
@@ -146,8 +146,7 @@
Integer[] result = entry.convertToType(Integer[].class, node, null);
assertNotNull(result);
- assertEquals(1, result.length);
- assertEquals(Integer.valueOf(2), result[0]);
+ assertEquals(0, result.length);
verifyZeroInteractions(node);
}