You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Brock Noland (JIRA)" <ji...@apache.org> on 2013/02/01 17:26:12 UTC
[jira] [Commented] (AVRO-1240) SpecificDataumReader.next() can
return a GenericData.Record resulting in a ClassCastException
[ https://issues.apache.org/jira/browse/AVRO-1240?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13568851#comment-13568851 ]
Brock Noland commented on AVRO-1240:
------------------------------------
I have found three work arounds for this issue.
Change
{noformat}
Test datum = null;
{noformat}
to
{noformat}
Test datum = new Test();
{noformat}
Change
{noformat}
DatumReader<Test> reader = new SpecificDatumReader<Test>(Test.class);
{noformat}
to:
{noformat}
DatumReader<Test> reader = new SpecificDatumReader<Test>(Test.SCHEMA$, Test.SCHEMA$, new SpecificData(Test.class.getClassLoader()));
{noformat}
Put the jar containing the specific class in the classpath of the main JVM
That is change:
{noformat}
$ 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
{noformat}
to
{noformat}
$ java -cp avro-1.7.3.jar:$(hadoop classpath):target/avro-example-1.0-jar-with-dependencies.jar org.apache.hadoop.util.RunJar target/avro-example-1.0-jar-with-dependencies.jar Sample target/test-file
{noformat}
or do the equivalent with the HADOOP_CLASSPATH variable.
> SpecificDataumReader.next() can return a GenericData.Record resulting in a ClassCastException
> ---------------------------------------------------------------------------------------------
>
> Key: AVRO-1240
> URL: https://issues.apache.org/jira/browse/AVRO-1240
> Project: Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.7.3
> Reporter: Brock Noland
> Assignee: Brock Noland
>
> The following reasonable code:
> {noformat}
> 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);
> }
> {noformat}
> Can result in a runtime exception:
> {noformat}
> $ 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)
> {noformat}
> 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.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira