You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (JIRA)" <ji...@apache.org> on 2016/06/16 06:25:05 UTC

[jira] [Commented] (CALCITE-1294) function gatherConstraint in class ReduceExpressionsRule throws NullPointerException when both left RexNode and right RexNode are NULL RexLiteral

    [ https://issues.apache.org/jira/browse/CALCITE-1294?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15333201#comment-15333201 ] 

Julian Hyde commented on CALCITE-1294:
--------------------------------------

Do you have a test case? I don't think that patch will compile, and it introduces a bug with an extra {{!}}.

> function gatherConstraint in class ReduceExpressionsRule throws NullPointerException when both left RexNode and right RexNode are NULL RexLiteral
> -------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-1294
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1294
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: chunwei
>            Assignee: Julian Hyde
>         Attachments: CALCITE-1294.patch
>
>
> function gatherConstraint in class ReduceExpressionsRule throw NullPointerException when both left RexNode and right RexNode are NULL RexLiteral.
> {code:title=ReduceExpressionsRule.java |borderStyle=solid}
>   private static <C extends RexNode> void gatherConstraint(Class<C> clazz,
>       RexNode left, RexNode right, Map<RexNode, C> map, Set<RexNode> excludeSet,
>       RexBuilder rexBuilder) {
>      ......
> else {
>       if (existedValue instanceof RexLiteral
>           && constant instanceof RexLiteral
>           && !((RexLiteral) existedValue).getValue()
>               .equals(((RexLiteral) constant).getValue())) {
>         // we found conflicting values, e.g. left = 10 and left = 20
>         map.remove(left);
>         excludeSet.add(left);
>       }
>     },
> }
> {code}
> when existedValue and constant are NULL RexLiteral, getValue() returns null and null.equals(null) will throw NullPointerException.
> It is better and safer to use 
> {noformat}
> ObjectUtils.equals(((RexLiteral) existedValue).getValue(), ((RexLiteral) constant).getValue()) 
> {noformat}
> than
> {noformat}
>  ((RexLiteral) existedValue).getValue().equals(((RexLiteral) constant).getValue())
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)