[
https://issues.apache.org/jira/browse/AVRO-1123?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13402493#comment-13402493
]
Steven Willis commented on AVRO-1123:
-------------------------------------
{code:title=SpecificRecord.java}
@Override
public Object newRecord(Object old, Schema schema) {
Class c = SpecificData.get().getClass(schema);
if (c == null) return super.newRecord(old, schema); // punt to generic
return (c.isInstance(old) ? old : newInstance(c, schema));
}
{code}
When {{SpecificData.get()}} is called, the singleton instance is returned,
which doesn't have the custom {{ClassLoader}} which was passed in to the
constructor of the instance of {{SpecificData}} making this call. I think it
should simply be changed to getClass(schema).
For example, I have:
{code:title=MyClass.java}
SpecificData specificData = new SpecificData(MyRecord.class.getClassLoader());
DatumReader<MyRecord> reader = new
SpecificDatumReader<MyRecord>(MyRecord.SCHEMA$,
MyRecord.SCHEMA$,
specificData);
DataFileStream<MyRecord> stream = new DataFileStream<MyRecord>(bufInStream,
reader);
for(MyRecord record : stream) {
System.out.printf("%s\n", record.field);
}
{code}
When run, I get: Exception in thread "main" java.lang.ClassCastException:
org.apache.avro.generic.GenericData$Record cannot be cast to
com.compete.avro.MyRecord
If I add the jar containing {{MyRecord.class}} to the classpath, then it works,
but I'd like to not have to do that since it should be found anyway.
> SpecificData is not using the custom ClassLoader in newRecord
> -------------------------------------------------------------
>
> Key: AVRO-1123
> URL: https://issues.apache.org/jira/browse/AVRO-1123
> Project: Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.6.0
> Reporter: Steven Willis
>
> AVRO-873 added support for a custom ClassLoader in SpecificData and a custom
> SpecificData in SpecificDatumReader. However the SpecificData doesn't use
> this custom ClassLoader in the newRecord method.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira