[ 
https://issues.apache.org/jira/browse/AVRO-2462?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16894635#comment-16894635
 ] 

Ryan Skraba commented on AVRO-2462:
-----------------------------------

It looks like support for Date as a "stringable" type was removed in AVRO-1155 
for good reason in 1.7.2.  I've checked that adding Date back to 
[stringableClasses](https://github.com/apache/avro/blob/2d3b1fe7efd865639663ba785877182e7e038c45/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java#L100)
 fixes this problem, but it looks like the best solution is "don't use Date as 
a "java-class" with type STRING", especially now that logical types for Dates 
exist.

Unfortunately, we _really_ do use "stringable" dates a lot in legacy code.  I'm 
going to take a look if there's a non-intrusive solution (hopefully on our end) 
to prevent this exception. It's unfortunate that this occurs in `hashCode`.

> Specific record hashCode() with union including "java-class" throws exception
> -----------------------------------------------------------------------------
>
>                 Key: AVRO-2462
>                 URL: https://issues.apache.org/jira/browse/AVRO-2462
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.7, 1.9.0
>            Reporter: Ryan Skraba
>            Assignee: Ryan Skraba
>            Priority: Major
>             Fix For: 1.9.1
>
>         Attachments: AVRO-2462-unit-test.patch
>
>
> Given a specific record generated from the following avsc:
> {code:java}
> {
>   "type": "record",
>   "name": "Lifetime",
>   "fields": [
>     {"name": "name", "type": "string"},
>     {"name": "birth",
>      "type": {"type": "string", "java-class": "java.util.Date"}},
>     {"name": "death",
>      "type": ["null", 
>               {"type": "string", "java-class": "java.util.Date"}],
>       "default": null
>     }
>   ]
> }{code}
> birth is a required field and death is a nullable field.
> The following code works (death is null):
> {code:java}
> Lifetime ws = Lifetime.newBuilder().setName("William Shakespeare")
>     .setBirth(new Date(-12801286800000L)).build();
> long x = ws.hashCode();{code}
> Setting the death field is broken:
> {code:java}
> ws.setDeath(new Date(-11161414800000L));
> long y = ws.hashCode();{code}
> The following exception is thrown:
> {code:java}
> org.apache.avro.AvroRuntimeException: Unknown datum type java.util.Date: Sat 
> Apr 23 00:00:00 CET 1616
> at org.apache.avro.generic.GenericData.getSchemaName(GenericData.java:887)
> at org.apache.avro.specific.SpecificData.getSchemaName(SpecificData.java:420)
> at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:850)
> at org.apache.avro.generic.GenericData.hashCode(GenericData.java:1059)
> at org.apache.avro.generic.GenericData.hashCodeAdd(GenericData.java:1073)
> at org.apache.avro.generic.GenericData.hashCode(GenericData.java:1049)
> at 
> org.apache.avro.specific.SpecificRecordBase.hashCode(SpecificRecordBase.java:84){code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to