Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CB64C200BEE for ; Fri, 16 Dec 2016 16:10:00 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id CA2C9160AF6; Fri, 16 Dec 2016 15:10:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 28FC3160B32 for ; Fri, 16 Dec 2016 16:10:00 +0100 (CET) Received: (qmail 60965 invoked by uid 500); 16 Dec 2016 15:09:59 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 60942 invoked by uid 99); 16 Dec 2016 15:09:59 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Dec 2016 15:09:59 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 0746F2C03DF for ; Fri, 16 Dec 2016 15:09:59 +0000 (UTC) Date: Fri, 16 Dec 2016 15:09:59 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@brooklyn.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (BROOKLYN-406) Coercion using fromMap(map) - exception thrown away, and value not coerced MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 16 Dec 2016 15:10:01 -0000 [ https://issues.apache.org/jira/browse/BROOKLYN-406?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15754652#comment-15754652 ] ASF GitHub Bot commented on BROOKLYN-406: ----------------------------------------- Github user neykov commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/477#discussion_r92826864 --- Diff: utils/common/src/test/java/org/apache/brooklyn/util/javalang/coerce/TypeCoercionsTest.java --- @@ -344,6 +344,59 @@ public void testFrom() { } @Test + public void testFromThrowingException() { + String expectedGenericErr = "Cannot coerce type class " + String.class.getName() + " to " + WithFromThrowingException.class.getCanonicalName(); + String expectedSpecificErr = "Simulating problem in fromString"; + + try { + coercer.coerce("myval", WithFromThrowingException.class); + Asserts.shouldHaveFailedPreviously(); + } catch (ClassCoercionException e) { + Asserts.expectedFailureContains(e, expectedGenericErr, expectedSpecificErr); + } + + try { + coercer.tryCoerce("myval", WithFromThrowingException.class).get(); + Asserts.shouldHaveFailedPreviously(); + } catch (ClassCoercionException e) { + Asserts.expectedFailureContains(e, expectedGenericErr, expectedSpecificErr); + } + } + + // TODO Asserting this undesirable behaviur, to preserve backwards compatibility! + // Would much prefer that we fail-fast. However, I worry that some entity's jave declared --- End diff -- typo `jave` > Coercion using fromMap(map) - exception thrown away, and value not coerced > -------------------------------------------------------------------------- > > Key: BROOKLYN-406 > URL: https://issues.apache.org/jira/browse/BROOKLYN-406 > Project: Brooklyn > Issue Type: Bug > Reporter: Aled Sage > Fix For: 0.9.0 > > > We had a {{ConfigKey>}}, and were setting that in YAML using a map. We expected {{VolumeOptions.fromMap(map)}} to be called as part of {{getConfig(VOLUMES, val)}}. This does indeed happen. > However, if {{VolumeOptions.fromMap(map)}} throws an exception (e.g. because the input data was malformed), it does not report any problems and instead the {{getConfig}} just returns a list containing uncoerced map objects. As a result, we subsequently got a {{ClassCastException}} in our entity code. > This was extremely hard to figure out - it involved attaching a debugger, breakpointing and stepping through the coercion code. > --- > Digging into the underlying cause, the problem is in this stacktrace: > {noformat} > "brooklyn-execmanager-PRYA08PS-104" daemon prio=5 tid=0x00007f82096c7000 nid=0x14f0b runnable [0x0000700005eac000] > java.lang.Thread.State: RUNNABLE > at org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible.tryCoerceWithFromMethod(TypeCoercerExtensible.java:204) > at org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible.tryCoerceInternal(TypeCoercerExtensible.java:135) > at org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible.tryCoerce(TypeCoercerExtensible.java:107) > at org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible.tryCoerceCollection(TypeCoercerExtensible.java:263) > at org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible.tryCoerceInternal(TypeCoercerExtensible.java:121) > at org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible.tryCoerce(TypeCoercerExtensible.java:107) > at org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible.coerce(TypeCoercerExtensible.java:97) > at org.apache.brooklyn.util.core.flags.TypeCoercions.coerce(TypeCoercions.java:80) > at org.apache.brooklyn.util.core.config.ConfigBag.coerceFirstNonNullKeyValue(ConfigBag.java:502) > at org.apache.brooklyn.util.core.config.ConfigBag.get(ConfigBag.java:496) > at org.apache.brooklyn.util.core.config.ConfigBag.get(ConfigBag.java:344) > {noformat} > The {{TypeCoercerExtensible.tryCoerceWithFromMethod}} accidentally throws away the exception! It is therefore treated as though there was no applicable coercion. However, because {{List}} can be cast to {{List}} then it returns it anyway. -- This message was sent by Atlassian JIRA (v6.3.4#6332)