Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-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 347A6183C6 for ; Mon, 20 Jul 2015 22:33:55 +0000 (UTC) Received: (qmail 99633 invoked by uid 500); 20 Jul 2015 22:32:56 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 99591 invoked by uid 500); 20 Jul 2015 22:32:56 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 99582 invoked by uid 99); 20 Jul 2015 22:32:56 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Jul 2015 22:32:56 +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 85A43AC0157 for ; Mon, 20 Jul 2015 22:32:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1692035 - /felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java Date: Mon, 20 Jul 2015 22:32:56 -0000 To: commits@felix.apache.org From: djencks@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150720223256.85A43AC0157@hades.apache.org> Author: djencks Date: Mon Jul 20 22:32:56 2015 New Revision: 1692035 URL: http://svn.apache.org/r1692035 Log: FELIX-4968 Throw coercion exceptions when members are accessed Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java?rev=1692035&r1=1692034&r2=1692035&view=diff ============================================================================== --- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java (original) +++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java Mon Jul 20 22:32:56 2015 @@ -54,19 +54,26 @@ public class Annotations complexFields.put(key, method); continue; } - if (returnType.isArray()) + try { - Class componentType = returnType.getComponentType(); - if ( componentType.isInterface() || componentType.isAnnotation()) + if (returnType.isArray()) { - complexFields.put(key, method); - continue; + Class componentType = returnType.getComponentType(); + if (componentType.isInterface() || componentType.isAnnotation()) + { + complexFields.put(key, method); + continue; + } + cooked = coerceToArray(componentType, raw, b); + } + else + { + cooked = Coercions.coerce(returnType, raw, b); } - cooked = coerceToArray(componentType, raw, b); } - else + catch (ComponentException e) { - cooked = Coercions.coerce( returnType, raw, b ); + cooked = new Invalid(e); } m.put( name, cooked ); } @@ -106,7 +113,7 @@ public class Annotations { for (Method method: complexFields.values()) { - m.put(method.getName(), Handler.INVALID); + m.put(method.getName(), new Invalid("Invalid annotation member type" + method.getReturnType().getName() + " for member: " + method.getName())); } } } @@ -213,9 +220,8 @@ public class Annotations return b.toString(); } - private static class Handler implements InvocationHandler + private final static class Handler implements InvocationHandler { - private final static Object INVALID = new Object(); private final Map values; public Handler(Map values) @@ -226,14 +232,33 @@ public class Annotations public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object value = values.get(method.getName()); - if (INVALID == value) + if (value instanceof Invalid) { - throw new ComponentException( - "Invalid annotation member type" + method.getReturnType().getName() + " for member: " + method.getName()); + throw new ComponentException(((Invalid)value).getMessage()); } return value; } } + + private final static class Invalid + { + private final String message; + + public Invalid(ComponentException e) + { + this.message = e.getMessage(); + } + + public Invalid(String message) + { + this.message = message; + } + + public String getMessage() + { + return message; + } + } }