From 37dba589f77b73f4cc642b65f7d024667eef9ffb Mon Sep 17 00:00:00 2001 From: Joerg Schaible Date: Thu, 12 Aug 2010 06:47:43 +0000 Subject: [PATCH] Fix wrong cast. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@984655 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/lang3/reflect/ConstructorUtils.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java b/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java index a51173eea..a6f1b6399 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/ConstructorUtils.java @@ -265,14 +265,13 @@ public class ConstructorUtils { } Constructor result = null; /* - * Class.getConstructors() is documented to return Constructor so as - * long as the array is not subsequently modified, everything's fine: + * (1) Class.getConstructors() is documented to return Constructor so as + * long as the array is not subsequently modified, everything's fine. */ - @SuppressWarnings("unchecked") // cls is of type T - Constructor[] ctors = cls.getConstructors(); + Constructor[] ctors = cls.getConstructors(); // return best match: - for (Constructor 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 constructor = (Constructor)ctor; + result = constructor; } } }