Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6FE59179A3 for ; Sat, 11 Apr 2015 10:15:37 +0000 (UTC) Received: (qmail 38588 invoked by uid 500); 11 Apr 2015 10:15:37 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 38528 invoked by uid 500); 11 Apr 2015 10:15:37 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 38519 invoked by uid 99); 11 Apr 2015 10:15:37 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 Apr 2015 10:15:37 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 1904AAC00B3 for ; Sat, 11 Apr 2015 10:15:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1672855 - /sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java Date: Sat, 11 Apr 2015 10:15:36 -0000 To: commits@sling.apache.org From: kwin@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150411101537.1904AAC00B3@hades.apache.org> Author: kwin Date: Sat Apr 11 10:15:36 2015 New Revision: 1672855 URL: http://svn.apache.org/r1672855 Log: SLING-4608 workaround for bug with type extraction on array types in Java < 7 Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java Modified: sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java?rev=1672855&r1=1672854&r2=1672855&view=diff ============================================================================== --- sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java (original) +++ sling/trunk/bundles/extensions/validation/core/src/main/java/org/apache/sling/validation/impl/util/ValidatorTypeUtil.java Sat Apr 11 10:15:36 2015 @@ -18,6 +18,8 @@ */ package org.apache.sling.validation.impl.util; +import java.lang.reflect.Array; +import java.lang.reflect.GenericArrayType; import java.lang.reflect.TypeVariable; import java.util.Map; import java.util.Map.Entry; @@ -42,10 +44,15 @@ public class ValidatorTypeUtil { if (entry.getKey().getGenericDeclaration() instanceof Class) { Class clazz = (Class)entry.getKey().getGenericDeclaration(); if (clazz.equals(Validator.class)) { + // Java6 doesn't return the class for array types due to this bug: http://bugs.java.com/view_bug.do?bug_id=5041784 + if (type instanceof GenericArrayType) { + // as a workaround make a new array class out of the generic component type encapsulated in the generic array type + type = Array.newInstance((Class) ((GenericArrayType)type).getGenericComponentType(), 0).getClass(); + } if (type instanceof Class) { return (Class)type; } - // type may also be a parmeterized type (e.g. for Collection), this is not allowed! + // type may also be a parameterized type (e.g. for Collection), this is not allowed! else { throw new IllegalArgumentException("Validators may not use parameterized types as type parameter. Only simple class types and arrays of class types are allowed."); }