You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jo...@apache.org on 2010/08/12 08:47:43 UTC

svn commit: r984655 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java

Author: joehni
Date: Thu Aug 12 06:47:43 2010
New Revision: 984655

URL: http://svn.apache.org/viewvc?rev=984655&view=rev
Log:
Fix wrong cast.

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java?rev=984655&r1=984654&r2=984655&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java Thu Aug 12 06:47:43 2010
@@ -265,14 +265,13 @@ public class ConstructorUtils {
         }
         Constructor<T> result = null;
         /*
-         * Class.getConstructors() is documented to return Constructor<T> so as
-         * long as the array is not subsequently modified, everything's fine:
+         * (1) Class.getConstructors() is documented to return Constructor<T> so as
+         * long as the array is not subsequently modified, everything's fine.
          */
-        @SuppressWarnings("unchecked") // cls is of type T
-        Constructor<T>[] ctors = cls.getConstructors();
+        Constructor<?>[] ctors = cls.getConstructors();
 
         // return best match:
-        for (Constructor<T> ctor : ctors) {
+        for (Constructor<?> ctor : ctors) {
             // compare parameters
             if (ClassUtils.isAssignable(parameterTypes, ctor.getParameterTypes(), true)) {
                 // get accessible version of constructor
@@ -282,7 +281,10 @@ public class ConstructorUtils {
                     if (result == null
                             || MemberUtils.compareParameterTypes(ctor.getParameterTypes(), result
                                     .getParameterTypes(), parameterTypes) < 0) {
-                        result = ctor;
+                        // temporary variable for annotation, see comment above (1)
+                        @SuppressWarnings("unchecked") 
+                        Constructor<T> constructor = (Constructor<T>)ctor;
+                        result = constructor;
                     }
                 }
             }



Re: svn commit: r984655 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java

Posted by sebb <se...@gmail.com>.
On 16 August 2010 15:21, Matt Benson <gu...@gmail.com> wrote:
>
> On Aug 16, 2010, at 4:50 AM, sebb wrote:
>
>> On 12 August 2010 07:47,  <jo...@apache.org> wrote:
>>> Author: joehni
>>> Date: Thu Aug 12 06:47:43 2010
>>> New Revision: 984655
>>>
>>> URL: http://svn.apache.org/viewvc?rev=984655&view=rev
>>> Log:
>>> Fix wrong cast.
>>
>> What was wrong with the cast?
>>
>
> Only that it was preventing the CI build from compiling.  ;)

I see now.

It is a Java 1.5/1.6 incompatibility.

Compiles fine with Eclipse when the compiler is set to 1.5 (which is
what I was using)

Also compiles OK with Sun Java 1.5:
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
Java HotSpot(TM) Client VM (build 1.5.0_22-b03, mixed mode)

However, it fails when compiled with Sun Java 1.6:
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

>
> -Matt
>
>>>
>>> Modified:
>>>    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
>>>
>>> Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
>>> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java?rev=984655&r1=984654&r2=984655&view=diff
>>> ==============================================================================
>>> --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java (original)
>>> +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java Thu Aug 12 06:47:43 2010
>>> @@ -265,14 +265,13 @@ public class ConstructorUtils {
>>>         }
>>>         Constructor<T> result = null;
>>>         /*
>>> -         * Class.getConstructors() is documented to return Constructor<T> so as
>>> -         * long as the array is not subsequently modified, everything's fine:
>>> +         * (1) Class.getConstructors() is documented to return Constructor<T> so as
>>> +         * long as the array is not subsequently modified, everything's fine.
>>>          */
>>> -        @SuppressWarnings("unchecked") // cls is of type T
>>> -        Constructor<T>[] ctors = cls.getConstructors();
>>> +        Constructor<?>[] ctors = cls.getConstructors();
>>>
>>>         // return best match:
>>> -        for (Constructor<T> ctor : ctors) {
>>> +        for (Constructor<?> ctor : ctors) {
>>>             // compare parameters
>>>             if (ClassUtils.isAssignable(parameterTypes, ctor.getParameterTypes(), true)) {
>>>                 // get accessible version of constructor
>>> @@ -282,7 +281,10 @@ public class ConstructorUtils {
>>>                     if (result == null
>>>                             || MemberUtils.compareParameterTypes(ctor.getParameterTypes(), result
>>>                                     .getParameterTypes(), parameterTypes) < 0) {
>>> -                        result = ctor;
>>> +                        // temporary variable for annotation, see comment above (1)
>>> +                        @SuppressWarnings("unchecked")
>>> +                        Constructor<T> constructor = (Constructor<T>)ctor;
>>> +                        result = constructor;
>>>                     }
>>>                 }
>>>             }
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r984655 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java

Posted by Matt Benson <gu...@gmail.com>.
On Aug 16, 2010, at 4:50 AM, sebb wrote:

> On 12 August 2010 07:47,  <jo...@apache.org> wrote:
>> Author: joehni
>> Date: Thu Aug 12 06:47:43 2010
>> New Revision: 984655
>> 
>> URL: http://svn.apache.org/viewvc?rev=984655&view=rev
>> Log:
>> Fix wrong cast.
> 
> What was wrong with the cast?
> 

Only that it was preventing the CI build from compiling.  ;)

-Matt

>> 
>> Modified:
>>    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
>> 
>> Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
>> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java?rev=984655&r1=984654&r2=984655&view=diff
>> ==============================================================================
>> --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java (original)
>> +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java Thu Aug 12 06:47:43 2010
>> @@ -265,14 +265,13 @@ public class ConstructorUtils {
>>         }
>>         Constructor<T> result = null;
>>         /*
>> -         * Class.getConstructors() is documented to return Constructor<T> so as
>> -         * long as the array is not subsequently modified, everything's fine:
>> +         * (1) Class.getConstructors() is documented to return Constructor<T> so as
>> +         * long as the array is not subsequently modified, everything's fine.
>>          */
>> -        @SuppressWarnings("unchecked") // cls is of type T
>> -        Constructor<T>[] ctors = cls.getConstructors();
>> +        Constructor<?>[] ctors = cls.getConstructors();
>> 
>>         // return best match:
>> -        for (Constructor<T> ctor : ctors) {
>> +        for (Constructor<?> ctor : ctors) {
>>             // compare parameters
>>             if (ClassUtils.isAssignable(parameterTypes, ctor.getParameterTypes(), true)) {
>>                 // get accessible version of constructor
>> @@ -282,7 +281,10 @@ public class ConstructorUtils {
>>                     if (result == null
>>                             || MemberUtils.compareParameterTypes(ctor.getParameterTypes(), result
>>                                     .getParameterTypes(), parameterTypes) < 0) {
>> -                        result = ctor;
>> +                        // temporary variable for annotation, see comment above (1)
>> +                        @SuppressWarnings("unchecked")
>> +                        Constructor<T> constructor = (Constructor<T>)ctor;
>> +                        result = constructor;
>>                     }
>>                 }
>>             }
>> 
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r984655 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java

Posted by sebb <se...@gmail.com>.
On 12 August 2010 07:47,  <jo...@apache.org> wrote:
> Author: joehni
> Date: Thu Aug 12 06:47:43 2010
> New Revision: 984655
>
> URL: http://svn.apache.org/viewvc?rev=984655&view=rev
> Log:
> Fix wrong cast.

What was wrong with the cast?

>
> Modified:
>    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
>
> Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java
> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java?rev=984655&r1=984654&r2=984655&view=diff
> ==============================================================================
> --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java (original)
> +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java Thu Aug 12 06:47:43 2010
> @@ -265,14 +265,13 @@ public class ConstructorUtils {
>         }
>         Constructor<T> result = null;
>         /*
> -         * Class.getConstructors() is documented to return Constructor<T> so as
> -         * long as the array is not subsequently modified, everything's fine:
> +         * (1) Class.getConstructors() is documented to return Constructor<T> so as
> +         * long as the array is not subsequently modified, everything's fine.
>          */
> -        @SuppressWarnings("unchecked") // cls is of type T
> -        Constructor<T>[] ctors = cls.getConstructors();
> +        Constructor<?>[] ctors = cls.getConstructors();
>
>         // return best match:
> -        for (Constructor<T> ctor : ctors) {
> +        for (Constructor<?> ctor : ctors) {
>             // compare parameters
>             if (ClassUtils.isAssignable(parameterTypes, ctor.getParameterTypes(), true)) {
>                 // get accessible version of constructor
> @@ -282,7 +281,10 @@ public class ConstructorUtils {
>                     if (result == null
>                             || MemberUtils.compareParameterTypes(ctor.getParameterTypes(), result
>                                     .getParameterTypes(), parameterTypes) < 0) {
> -                        result = ctor;
> +                        // temporary variable for annotation, see comment above (1)
> +                        @SuppressWarnings("unchecked")
> +                        Constructor<T> constructor = (Constructor<T>)ctor;
> +                        result = constructor;
>                     }
>                 }
>             }
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org