avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Doug Cutting (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (AVRO-887) ReflectData.findField needs better error message
Date Wed, 21 Sep 2011 20:45:09 GMT

     [ https://issues.apache.org/jira/browse/AVRO-887?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Doug Cutting updated AVRO-887:
------------------------------

    Resolution: Fixed
        Status: Resolved  (was: Patch Available)

I committed this.

> ReflectData.findField needs better error message
> ------------------------------------------------
>
>                 Key: AVRO-887
>                 URL: https://issues.apache.org/jira/browse/AVRO-887
>             Project: Avro
>          Issue Type: Improvement
>          Components: java
>    Affects Versions: 1.5.3
>            Reporter: Chris Wilkes
>            Assignee: Doug Cutting
>            Priority: Trivial
>             Fix For: 1.6.0
>
>         Attachments: AVRO-887.patch
>
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> In this method:
>   Field findField(Class c, String name)
> a loop is done over c, replacing it each time with c = c.getSuperClass() and exiting
if null.  This means that at the end of the loop c will always be null.  The exception message
is then always
>   No field named XXX in null
> The fix is trivial:
>   private static Field findField(Class c, String name) {
>      Class originalClass = c;
>     do {
>       try {
>         Field f = c.getDeclaredField(name);
>         f.setAccessible(true);
>         return f;
>       } catch (NoSuchFieldException e) {}
>       c = c.getSuperclass();
>     } while (c != null);
>     throw new AvroRuntimeException("No field named "+name+" in: "+originalClass);
>   }

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message