diff options
author | Claude Brisson <cbrisson@apache.org> | 2016-12-02 17:26:34 +0000 |
---|---|---|
committer | Claude Brisson <cbrisson@apache.org> | 2016-12-02 17:26:34 +0000 |
commit | 6c4e44eb70fb5eff4e26f0c47fc48b99159fa395 (patch) | |
tree | 811e54273b573747f298c96fb8a2fd5f60345f59 /velocity-engine-core/src | |
parent | e0acd113835b491cd9917df1c0f631b08645f3fa (diff) | |
download | apache-velocity-engine-6c4e44eb70fb5eff4e26f0c47fc48b99159fa395.tar.gz |
[engine] be nicer with upberspectors that don't check that the base object is not null
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1772379 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src')
-rw-r--r-- | velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java index 0c9d37f7..d84a36f9 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java @@ -297,17 +297,8 @@ public class ASTReference extends SimpleNode if (result == null && !strictRef) // If strict and null then well catch this // next time through the loop { - // do not call bad reference handler if the getter is present - // (it means the getter has been called and returned null) - // do not either for a quiet reference or if the *last* child failed while testing the reference - Object getter = context.icacheGet(jjtGetChild(i)); - if (getter == null && - referenceType != QUIET_REFERENCE && - (!onlyTestingReference || i < jjtGetNumChildren() - 1)) - { - failedChild = i; - break; - } + failedChild = i; + break; } } @@ -328,32 +319,42 @@ public class ASTReference extends SimpleNode } else { - StringBuffer name = new StringBuffer("$").append(rootString); - for (int i = 0; i <= failedChild; i++) + Node child = jjtGetChild(failedChild); + // do not call bad reference handler if the getter is present + // (it means the getter has been called and returned null) + // do not either for a quiet reference or if the *last* child failed while testing the reference + Object getter = context.icacheGet(child); + if (getter == null && + referenceType != QUIET_REFERENCE && + (!onlyTestingReference || failedChild < jjtGetNumChildren() - 1)) { - Node node = jjtGetChild(i); - if (node instanceof ASTMethod) + StringBuffer name = new StringBuffer("$").append(rootString); + for (int i = 0; i <= failedChild; i++) + { + Node node = jjtGetChild(i); + if (node instanceof ASTMethod) + { + name.append(".").append(((ASTMethod) node).getMethodName()).append("()"); + } + else + { + name.append(".").append(node.getFirstTokenImage()); + } + } + + if (child instanceof ASTMethod) { - name.append(".").append(((ASTMethod) node).getMethodName()).append("()"); + String methodName = ((ASTMethod) jjtGetChild(failedChild)).getMethodName(); + result = EventHandlerUtil.invalidMethod(rsvc, context, + name.toString(), previousResult, methodName, uberInfo); } else { - name.append(".").append(node.getFirstTokenImage()); + String property = jjtGetChild(failedChild).getFirstTokenImage(); + result = EventHandlerUtil.invalidGetMethod(rsvc, context, + name.toString(), previousResult, property, uberInfo); } } - - if (jjtGetChild(failedChild) instanceof ASTMethod) - { - String methodName = ((ASTMethod) jjtGetChild(failedChild)).getMethodName(); - result = EventHandlerUtil.invalidMethod(rsvc, context, - name.toString(), previousResult, methodName, uberInfo); - } - else - { - String property = jjtGetChild(failedChild).getFirstTokenImage(); - result = EventHandlerUtil.invalidGetMethod(rsvc, context, - name.toString(), previousResult, property, uberInfo); - } } } |