Uploaded image for project: 'Brooklyn'
  1. Brooklyn
  2. BROOKLYN-406

Coercion using fromMap(map) - exception thrown away, and value not coerced

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 0.11.0
    • None

    Description

      We had a ConfigKey<List<VolumeOptions>>, 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:

      "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)
      

      The TypeCoercerExtensible.tryCoerceWithFromMethod accidentally throws away the exception! It is therefore treated as though there was no applicable coercion. However, because List<Map> can be cast to List then it returns it anyway.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              aled.sage Aled Sage
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: