Avro
  1. Avro
  2. AVRO-1240

SpecificDataumReader.next() can return a GenericData.Record resulting in a ClassCastException

    Details

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

      Description

      The following reasonable code:

          DatumReader<Test> reader = new SpecificDatumReader<Test>(Test.class); 
          DataFileReader<Test> dataFileReader = new DataFileReader<Test>(file, reader); 
          Test datum = null;
          while(dataFileReader.hasNext()) { 
            datum = dataFileReader.next(datum); 
            System.out.println(datum); 
          }
      

      Can result in a runtime exception:

      $ java -cp avro-1.7.3.jar:$(hadoop classpath) org.apache.hadoop.util.RunJar target/avro-example-1.0-jar-with-dependencies.jar Sample target/test-file 
      Exception in thread "main" java.lang.ClassCastException: org.apache.avro.generic.GenericData$Record cannot be cast to Test
      	at Sample.main(Sample.java:27)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.apache.hadoop.util.RunJar.main(RunJar.java:208)
      

      when the jar containing the specific class (Test in my example) is loaded from a different classloader than the avro jar itself. This occurs when run via the hadoop jar command but could occur in web containers or other locations as well.

      1. AVRO-1240.patch
        3 kB
        Doug Cutting

        Issue Links

          Activity

          Brock Noland created issue -
          Brock Noland made changes -
          Field Original Value New Value
          Link This issue relates to AVRO-1103 [ AVRO-1103 ]
          Doug Cutting made changes -
          Attachment AVRO-1240.patch [ 12567607 ]
          Doug Cutting made changes -
          Status Open [ 1 ] Patch Available [ 10002 ]
          Fix Version/s 1.7.4 [ 12323742 ]
          Brock Noland made changes -
          Assignee Brock Noland [ brocknoland ] Doug Cutting [ cutting ]
          Doug Cutting made changes -
          Status Patch Available [ 10002 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Doug Cutting made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              Doug Cutting
              Reporter:
              Brock Noland
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development