commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Carman (JIRA)" <j...@apache.org>
Subject [jira] Commented: (BEANUTILS-309) Passing a null argument to ConstructorUtils.invokeConstructor causes NullPointerException
Date Wed, 05 Mar 2008 13:37:40 GMT

    [ https://issues.apache.org/jira/browse/BEANUTILS-309?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12575336#action_12575336
] 

James Carman commented on BEANUTILS-309:
----------------------------------------

Even the Java language doesn't allow you to do what you're trying to do here (without some
qualification):

public class Foo
{
    public Foo(String param)
    {
    }

    public Foo(Integer param)
    {
    }

    public static void main(String[] args)
    {
        new Foo(null).toString();
    }
}

This results in :

Error:Error:line (17)reference to Foo is ambiguous, both method Foo(java.lang.String) in Foo
and method Foo(java.lang.Integer) in Foo match

You have to cast the parameter so that the compiler knows what you're trying to do ("this
is a String non-object"):

new Foo((String)null).toString();

which is essentially what you'd be doing by calling the invokeConstructor(Class,Object[],Class[])
method. 

> Passing a null argument to ConstructorUtils.invokeConstructor causes NullPointerException
> -----------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-309
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-309
>             Project: Commons BeanUtils
>          Issue Type: Bug
>    Affects Versions: 1.7.0, 1.8.0-BETA
>            Reporter: Xavier Poinsard
>
> I am invoking ConstructorUtils.invokeConstructor with an array of arguments and one of
these arguments is null.
> This causes a NullPointerException line 120 in Class ConstructorUtils.
> Since its not forbidden to pass null argument to a constructor, ConstructorUtils should
handle it.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message