You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2013/02/24 12:29:04 UTC
svn commit: r1449456 - in /commons/proper/beanutils/trunk/src:
changes/changes.xml
main/java/org/apache/commons/beanutils/ConstructorUtils.java
test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java
Author: britter
Date: Sun Feb 24 11:29:04 2013
New Revision: 1449456
URL: http://svn.apache.org/r1449456
Log:
[BEANUTILS-426] - ConstructorUtils.invokeConstructor(Class klass, Object arg) throws NullPointerException when arg==null
Modified:
commons/proper/beanutils/trunk/src/changes/changes.xml
commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/ConstructorUtils.java
commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java
Modified: commons/proper/beanutils/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/changes/changes.xml?rev=1449456&r1=1449455&r2=1449456&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/changes/changes.xml (original)
+++ commons/proper/beanutils/trunk/src/changes/changes.xml Sun Feb 24 11:29:04 2013
@@ -40,6 +40,10 @@ The <action> type attribute can be add,u
<body>
<release version="1.8.4" date="in SVN" description="Bug fix for 1.8.3">
+ <action dev="britter" type="fix" issue="BEANUTILS-426" >
+ ConstructorUtils.invokeConstructor(Class klass, Object arg) throws
+ NullPointerException when arg==null
+ </action>
<action dev="niallp" type="fix" issue="BEANUTILS-380" due-to="Brendan Nolan">
BeanMap methods should initialize the root cause of exceptions that are thrown
when running on JDK 1.4+
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/ConstructorUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/ConstructorUtils.java?rev=1449456&r1=1449455&r2=1449456&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/ConstructorUtils.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/ConstructorUtils.java Sun Feb 24 11:29:04 2013
@@ -82,6 +82,9 @@ public class ConstructorUtils {
InstantiationException {
Object[] args = { arg };
+ if (arg == null) {
+ args = null;
+ }
return invokeConstructor(klass, args);
}
Modified: commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java?rev=1449456&r1=1449455&r2=1449456&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java (original)
+++ commons/proper/beanutils/trunk/src/test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java Sun Feb 24 11:29:04 2013
@@ -88,6 +88,12 @@ public class ConstructorUtilsTestCase ex
}
}
+ public void testInvokeConstructorNull() throws Exception {
+ Object obj = ConstructorUtils.invokeConstructor(TestBean.class, (Object) null);
+ assertNotNull(obj);
+ assertTrue(obj instanceof TestBean);
+ }
+
public void testInvokeConstructorWithArgArray() throws Exception {
Object[] args = { new Float(17.3f), "TEST" };
Object obj = ConstructorUtils.invokeConstructor(TestBean.class,args);
Re: svn commit: r1449456 - in /commons/proper/beanutils/trunk/src:
changes/changes.xml main/java/org/apache/commons/beanutils/ConstructorUtils.java
test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java
Posted by Benedikt Ritter <br...@apache.org>.
2013/2/25 Jörg Schaible <Jo...@scalaris.com>
> Benedikt Ritter wrote:
>
> > Hi Simo,
> >
> > 2013/2/24 Simone Tripodi <si...@apache.org>
> >
> >> Hi there Bene,
> >>
> >> > @@ -82,6 +82,9 @@ public class ConstructorUtils {
> >> > InstantiationException {
> >> >
> >> > Object[] args = { arg };
> >> > + if (arg == null) {
> >> > + args = null;
> >> > + }
> >> > return invokeConstructor(klass, args);
> >> > }
> >>
> >> I'd invert the logic to
> >>
> >> Object[] args = null;
> >> if (arg != null) {
> >> args = { arg };
> >> }
> >> return invokeConstructor(klass, args);
> >>
> >
> > In fact this is what I implemented first but the compiler won't let you
> do
> > this:
> > Array constants can only be used in initializers.
> >
> > I don't like my solution to much, because it is a bit counter intuitive.
> > But as the compile tells you why this is implemented this why, I think it
> > can stay like this. WDYT?
>
> You might use "new Object[]{arg}". In the end the compiler does the same.
>
>
yep, that's better. I'll change it when I'm at home.
> Cheers,
> Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
--
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter
Re: svn commit: r1449456 - in /commons/proper/beanutils/trunk/src:
changes/changes.xml main/java/org/apache/commons/beanutils/ConstructorUtils.java
test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java
Posted by Simone Tripodi <si...@apache.org>.
> You might use "new Object[]{arg}". In the end the compiler does the same.
>
+1
> Cheers,
> Jörg
http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1449456 - in /commons/proper/beanutils/trunk/src: changes/changes.xml main/java/org/apache/commons/beanutils/ConstructorUtils.java test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java
Posted by Jörg Schaible <Jo...@scalaris.com>.
Benedikt Ritter wrote:
> Hi Simo,
>
> 2013/2/24 Simone Tripodi <si...@apache.org>
>
>> Hi there Bene,
>>
>> > @@ -82,6 +82,9 @@ public class ConstructorUtils {
>> > InstantiationException {
>> >
>> > Object[] args = { arg };
>> > + if (arg == null) {
>> > + args = null;
>> > + }
>> > return invokeConstructor(klass, args);
>> > }
>>
>> I'd invert the logic to
>>
>> Object[] args = null;
>> if (arg != null) {
>> args = { arg };
>> }
>> return invokeConstructor(klass, args);
>>
>
> In fact this is what I implemented first but the compiler won't let you do
> this:
> Array constants can only be used in initializers.
>
> I don't like my solution to much, because it is a bit counter intuitive.
> But as the compile tells you why this is implemented this why, I think it
> can stay like this. WDYT?
You might use "new Object[]{arg}". In the end the compiler does the same.
Cheers,
Jörg
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1449456 - in /commons/proper/beanutils/trunk/src:
changes/changes.xml main/java/org/apache/commons/beanutils/ConstructorUtils.java
test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java
Posted by Benedikt Ritter <br...@apache.org>.
Hi Simo,
2013/2/24 Simone Tripodi <si...@apache.org>
> Hi there Bene,
>
> > @@ -82,6 +82,9 @@ public class ConstructorUtils {
> > InstantiationException {
> >
> > Object[] args = { arg };
> > + if (arg == null) {
> > + args = null;
> > + }
> > return invokeConstructor(klass, args);
> > }
>
> I'd invert the logic to
>
> Object[] args = null;
> if (arg != null) {
> args = { arg };
> }
> return invokeConstructor(klass, args);
>
In fact this is what I implemented first but the compiler won't let you do
this:
Array constants can only be used in initializers.
I don't like my solution to much, because it is a bit counter intuitive.
But as the compile tells you why this is implemented this why, I think it
can stay like this. WDYT?
Thanks!
Benedikt
>
> HTH,
> -Simo
>
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
--
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter
Re: svn commit: r1449456 - in /commons/proper/beanutils/trunk/src:
changes/changes.xml main/java/org/apache/commons/beanutils/ConstructorUtils.java
test/java/org/apache/commons/beanutils/ConstructorUtilsTestCase.java
Posted by Simone Tripodi <si...@apache.org>.
Hi there Bene,
> @@ -82,6 +82,9 @@ public class ConstructorUtils {
> InstantiationException {
>
> Object[] args = { arg };
> + if (arg == null) {
> + args = null;
> + }
> return invokeConstructor(klass, args);
> }
I'd invert the logic to
Object[] args = null;
if (arg != null) {
args = { arg };
}
return invokeConstructor(klass, args);
HTH,
-Simo
http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org