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

ASF GitHub Bot commented on DRILL-5330:
---------------------------------------

GitHub user paul-rogers opened a pull request:

    https://github.com/apache/drill/pull/777

    DRILL-5330: NPE in FunctionImplementationRegistry

    Fixes:
    
    * DRILL-5330: NPE in
    FunctionImplementationRegistry.functionReplacement()
    * DRILL-5331:
    NPE in FunctionImplementationRegistry.findDrillFunction() if dynamic
    UDFs disabled
    
    For DRILL-5331, we leverage an existing session option to determine if
    DUDFs are enabled. If not, we skip the DUDF registry check.
    
    For DRILL-5330, we use an existing option validator rather than
    accessing the raw option directly.
    
    Then, both options cached on setup rather than repeatedly resolved in
    each function lookup.
    
    Also includes a bit of code cleanup in the class in question.
    
    The result is that the code now works when used in a sub-operator unit
    test.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/paul-rogers/drill DRILL-5330

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/drill/pull/777.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #777
    
----
commit 8d2d9093dd26582fa7b13fe6fb57428f9a90d170
Author: Paul Rogers <[email protected]>
Date:   2017-03-10T19:55:13Z

    DRILL-5330: NPE in FunctionImplementationRegistry
    
    Fixes:
    
    * DRILL-5330: NPE in
    FunctionImplementationRegistry.functionReplacement()
    * DRILL-5331:
    NPE in FunctionImplementationRegistry.findDrillFunction() if dynamic
    UDFs disabled
    
    For DRILL-5331, we leverage an existing session option to determine if
    DUDFs are enabled. If not, we skip the DUDF registry check.
    
    For DRILL-5330, we use an existing option validator rather than
    accessing the raw option directly.
    
    Then, both options cached on setup rather than repeatedly resolved in
    each function lookup.
    
    Also includes a bit of code cleanup in the class in question.
    
    The result is that the code now works when used in a sub-operator unit
    test.

----


> NPE in FunctionImplementationRegistry.functionReplacement()
> -----------------------------------------------------------
>
>                 Key: DRILL-5330
>                 URL: https://issues.apache.org/jira/browse/DRILL-5330
>             Project: Apache Drill
>          Issue Type: Bug
>    Affects Versions: 1.10.0
>            Reporter: Paul Rogers
>            Assignee: Paul Rogers
>             Fix For: 1.11.0
>
>
> The code in {{FunctionImplementationRegistry.functionReplacement()}} will 
> produce an NPE if ever it is called:
> {code}
>           if (optionManager != null
>               && optionManager.getOption(
>                    ExecConstants.CAST_TO_NULLABLE_NUMERIC).bool_val
>               ...
> {code}
> If an option manager is provided, then get the specified option. The option 
> manager will contain a value for that option only if the user has explicitly 
> set that option. Suppose the user had not set the option. Then the return 
> from {{getOption()}} will be null.
> The next thing we do is *assume* that the option exists and is a boolean by 
> dereferencing the option. This will trigger an NPE. This NPE was seen in 
> detail-level unit tests.
> The proper way to handle such options is to use an option validator. 
> Strangely, one actually exists in {{ExecConstants}}:
> {code}
>   String CAST_TO_NULLABLE_NUMERIC = 
> "drill.exec.functions.cast_empty_string_to_null";
>   OptionValidator CAST_TO_NULLABLE_NUMERIC_OPTION = new 
> BooleanValidator(CAST_TO_NULLABLE_NUMERIC, false);
> {code}
> Then do:
> {code}
> optionManager.getOption(
>          ExecConstants.CAST_TO_NULLABLE_NUMERIC_OPTION)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to