Uploaded image for project: 'Crunch'
  1. Crunch
  2. CRUNCH-548

getDetachedValue calls to AvroReflectDeepCopier throw InstantiationException on non-concrete types

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.13.0
    • Component/s: None
    • Labels:
      None

      Description

      A common use case with avro reflection is to operate on an abstract class or interface which is serialized using a schema based on a concrete subclass (or union of subclasses).

      @org.apache.avro.reflect.Union(

      { Foo1.class }

      )
      public interface Foo {
      public String getFoo();
      }
      public class Foo1 implements Foo {
      private final Double value = 1.0;
      @Override
      public String getFoo()

      { return value.toString(); }

      }

      When trying to operate on this type within crunch, calls to getDetachedValue() will throw an InstantiationException:

      AvroType<Foo> ptype = Avros.reflects(Foo.class, ReflectData.get().getSchema(Foo.class));
      ptype.initialize(new Configuration());
      Foo copy1 = ptype.getDetachedValue(new Foo1());

      Exception in thread "main" org.apache.crunch.CrunchRuntimeException: java.lang.InstantiationException: org.mitre.caasd.tt.DeepCopyTest$Foo
      at org.apache.crunch.types.avro.AvroDeepCopier$AvroReflectDeepCopier.createNewInstance(AvroDeepCopier.java:158)

      One solution would be to augment the createNewInstance() method in AvroReflectDeepCopier to create a new instance based on the source object class, rather than the type class. This would generally be desirable for any union cases where the source is a subclass of the type class.

        Attachments

        1. CRUNCH-548.patch
          2 kB
          Josh Wills
        2. CRUNCH-548b.patch
          4 kB
          Josh Wills

          Activity

            People

            • Assignee:
              jwills Josh Wills
              Reporter:
              aeckstein Adric Eckstein
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: