Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 37392 invoked from network); 2 Feb 2010 20:40:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Feb 2010 20:40:07 -0000 Received: (qmail 53090 invoked by uid 500); 2 Feb 2010 20:40:06 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 53010 invoked by uid 500); 2 Feb 2010 20:40:06 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 53001 invoked by uid 99); 2 Feb 2010 20:40:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Feb 2010 20:40:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Feb 2010 20:40:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A22DA2388A16; Tue, 2 Feb 2010 20:39:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r905786 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java Date: Tue, 02 Feb 2010 20:39:41 -0000 To: commits@commons.apache.org From: mbenson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100202203945.A22DA2388A16@eris.apache.org> Author: mbenson Date: Tue Feb 2 20:39:36 2010 New Revision: 905786 URL: http://svn.apache.org/viewvc?rev=905786&view=rev Log: remove pre Java 5 workaround Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java?rev=905786&r1=905785&r2=905786&view=diff ============================================================================== --- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java (original) +++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java Tue Feb 2 20:39:36 2010 @@ -18,16 +18,14 @@ import java.lang.reflect.AccessibleObject; import java.lang.reflect.Member; -import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ClassUtils; -import org.apache.commons.lang3.SystemUtils; /** * Contains common code for working with Methods/Constructors, extracted and - * refactored from MethodUtils when it was imported from Commons BeanUtils. + * refactored from MethodUtils when it was imported from Commons + * BeanUtils. * * @author Apache Software Foundation * @author Steve Cohen @@ -40,35 +38,20 @@ private static final int ACCESS_TEST = Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE; - private static final Method IS_SYNTHETIC; - static { - Method isSynthetic = null; - if (SystemUtils.isJavaVersionAtLeast(1.5f)) { - // cannot call synthetic methods: - try { - isSynthetic = Member.class.getMethod("isSynthetic", - ArrayUtils.EMPTY_CLASS_ARRAY); - } catch (Exception e) { - } - } - IS_SYNTHETIC = isSynthetic; - } - /** Array of primitive number types ordered by "promotability" */ - private static final Class[] ORDERED_PRIMITIVE_TYPES = { Byte.TYPE, - Short.TYPE, Character.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, - Double.TYPE }; + private static final Class[] ORDERED_PRIMITIVE_TYPES = { Byte.TYPE, Short.TYPE, + Character.TYPE, Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE }; /** * XXX Default access superclass workaround * - * When a public class has a default access superclass with public - * members, these members are accessible. Calling them from - * compiled code works fine. Unfortunately, on some JVMs, using reflection to invoke these - * members seems to (wrongly) to prevent access even when the - * modifer is public. Calling setAccessible(true) solves the problem - * but will only work from sufficiently privileged code. Better - * workarounds would be gratefully accepted. + * When a public class has a default access superclass with public members, + * these members are accessible. Calling them from compiled code works fine. + * Unfortunately, on some JVMs, using reflection to invoke these members + * seems to (wrongly) to prevent access even when the modifer is public. + * Calling setAccessible(true) solves the problem but will only work from + * sufficiently privileged code. Better workarounds would be gratefully + * accepted. * @param o the AccessibleObject to set as accessible */ static void setAccessibleWorkaround(AccessibleObject o) { @@ -76,7 +59,8 @@ return; } Member m = (Member) o; - if (Modifier.isPublic(m.getModifiers()) && isPackageAccess(m.getDeclaringClass().getModifiers())) { + if (Modifier.isPublic(m.getModifiers()) + && isPackageAccess(m.getDeclaringClass().getModifiers())) { try { o.setAccessible(true); } catch (SecurityException e) { @@ -100,33 +84,19 @@ * @return true if m is accessible */ static boolean isAccessible(Member m) { - return m != null && Modifier.isPublic(m.getModifiers()) - && !isSynthetic(m); - } - - /** - * Try to learn whether a given member, on JDK >= 1.5, is synthetic. - * @param m Member to check - * @return true if m was introduced by the compiler. - */ - static boolean isSynthetic(Member m) { - if (IS_SYNTHETIC != null) { - try { - return ((Boolean) IS_SYNTHETIC.invoke(m, (Object[]) null)).booleanValue(); - } catch (Exception e) { - } - } - return false; + return m != null && Modifier.isPublic(m.getModifiers()) && !m.isSynthetic(); } /** * Compare the relative fitness of two sets of parameter types in terms of * matching a third set of runtime parameter types, such that a list ordered - * by the results of the comparison would return the best match first (least). + * by the results of the comparison would return the best match first + * (least). * * @param left the "left" parameter set * @param right the "right" parameter set - * @param actual the runtime parameter types to match against left/right + * @param actual the runtime parameter types to match against + * left/right * @return int consistent with compare semantics */ static int compareParameterTypes(Class[] left, Class[] right, Class[] actual) { @@ -136,14 +106,13 @@ } /** - * Returns the sum of the object transformation cost for each class in the source - * argument list. + * Returns the sum of the object transformation cost for each class in the + * source argument list. * @param srcArgs The source arguments * @param destArgs The destination arguments * @return The total transformation cost */ - private static float getTotalTransformationCost(Class[] srcArgs, - Class[] destArgs) { + private static float getTotalTransformationCost(Class[] srcArgs, Class[] destArgs) { float totalCost = 0.0f; for (int i = 0; i < srcArgs.length; i++) { Class srcClass, destClass; @@ -155,22 +124,20 @@ } /** - * Gets the number of steps required needed to turn the source class into the - * destination class. This represents the number of steps in the object hierarchy - * graph. + * Gets the number of steps required needed to turn the source class into + * the destination class. This represents the number of steps in the object + * hierarchy graph. * @param srcClass The source class * @param destClass The destination class * @return The cost of transforming an object */ - private static float getObjectTransformationCost(Class srcClass, - Class destClass) { + private static float getObjectTransformationCost(Class srcClass, Class destClass) { if (destClass.isPrimitive()) { return getPrimitivePromotionCost(srcClass, destClass); } float cost = 0.0f; while (destClass != null && !destClass.equals(srcClass)) { - if (destClass.isInterface() - && ClassUtils.isAssignable(srcClass, destClass)) { + if (destClass.isInterface() && ClassUtils.isAssignable(srcClass, destClass)) { // slight penalty for interface match. // we still want an exact match to override an interface match, // but @@ -193,13 +160,13 @@ } /** - * Get the number of steps required to promote a primitive number to another type. + * Get the number of steps required to promote a primitive number to another + * type. * @param srcClass the (primitive) source class * @param destClass the (primitive) destination class * @return The cost of promoting the primitive */ - private static float getPrimitivePromotionCost(final Class srcClass, - final Class destClass) { + private static float getPrimitivePromotionCost(final Class srcClass, final Class destClass) { float cost = 0.0f; Class cls = srcClass; if (!cls.isPrimitive()) {