You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2018/01/19 14:02:37 UTC
[sling-org-apache-sling-scripting-sightly] branch master updated:
SLING-7404 - ObjectModel and similar classes need consistent null checks
This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git
The following commit(s) were added to refs/heads/master by this push:
new d8bfb67 SLING-7404 - ObjectModel and similar classes need consistent null checks
d8bfb67 is described below
commit d8bfb677e688c885efd03affd127175ed6ac63ab
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Jan 19 14:37:19 2018 +0100
SLING-7404 - ObjectModel and similar classes need consistent null checks
(closes #1)
---
.../impl/engine/runtime/SlingRuntimeObjectModel.java | 3 +++
.../engine/runtime/SlingRuntimeObjectModelTest.java | 17 +++++++++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/SlingRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/SlingRuntimeObjectModel.java
index 3f491e6..cfe9cca 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/SlingRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/runtime/SlingRuntimeObjectModel.java
@@ -26,6 +26,9 @@ public class SlingRuntimeObjectModel extends AbstractRuntimeObjectModel {
@Override
protected Object getProperty(Object target, Object propertyObj) {
+ if (target == null || propertyObj == null) {
+ return null;
+ }
Object result = super.getProperty(target, propertyObj);
if (result == null && target instanceof Adaptable) {
ValueMap valueMap = ((Adaptable) target).adaptTo(ValueMap.class);
diff --git a/src/test/java/org/apache/sling/scripting/sightly/impl/engine/runtime/SlingRuntimeObjectModelTest.java b/src/test/java/org/apache/sling/scripting/sightly/impl/engine/runtime/SlingRuntimeObjectModelTest.java
index 8987d60..e396c2a 100644
--- a/src/test/java/org/apache/sling/scripting/sightly/impl/engine/runtime/SlingRuntimeObjectModelTest.java
+++ b/src/test/java/org/apache/sling/scripting/sightly/impl/engine/runtime/SlingRuntimeObjectModelTest.java
@@ -36,21 +36,30 @@ public class SlingRuntimeObjectModelTest {
private SlingRuntimeObjectModel slingRuntimeObjectModel = new SlingRuntimeObjectModel();
@Test
- public void getPropertyFromAdaptableWithField() throws Exception {
+ public void getPropertyFromAdaptableWithField() {
assertEquals("Expected public fields to have priority over ValueMap adaptable's properties.", FieldTestMockAdaptable.test,
slingRuntimeObjectModel.getProperty(new FieldTestMockAdaptable(), "test"));
}
@Test
- public void getPropertyFromAdaptableWithMethod() throws Exception {
+ public void getPropertyFromAdaptableWithMethod() {
assertEquals("Expected public methods to have priority over ValueMap adaptable's properties.", METHOD_VALUE,
slingRuntimeObjectModel.getProperty(new MethodTestMockAdaptable(), "test"));
- }@Test
- public void getPropertyFromAdaptable() throws Exception {
+ }
+
+ @Test
+ public void getPropertyFromAdaptable() {
assertEquals("Expected to solve property from ValueMap returned by an adaptable.", VALUE_MAP_VALUE,
slingRuntimeObjectModel.getProperty(new AdaptableTestMock(), "test"));
}
+ @Test
+ public void nullChecks() {
+ assertNull(slingRuntimeObjectModel.getProperty(null, null));
+ assertNull(slingRuntimeObjectModel.getProperty(this, null));
+ assertNull(slingRuntimeObjectModel.getProperty(this, ""));
+ }
+
private abstract class MockAdaptable implements Adaptable {
ValueMap getValueMap() {
--
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].