You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by "Richard Eckart de Castilho (JIRA)" <de...@uima.apache.org> on 2016/05/08 19:30:12 UTC

[jira] [Commented] (UIMA-4919) NPE when calling org.apache.uima.fit.internal.ReflectionUtil.getFields( Class clz ) on interface class.

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

Richard Eckart de Castilho commented on UIMA-4919:
--------------------------------------------------

Did you observe this exception being triggered by regular use of uimaFIT API, or did you use ReflectionUtil.getFields(...) directly?

> NPE when calling org.apache.uima.fit.internal.ReflectionUtil.getFields( Class<? extends Resource> clz ) on interface class.
> ---------------------------------------------------------------------------------------------------------------------------
>
>                 Key: UIMA-4919
>                 URL: https://issues.apache.org/jira/browse/UIMA-4919
>             Project: UIMA
>          Issue Type: Bug
>          Components: uimaFIT
>    Affects Versions: 2.2.0uimaFIT
>         Environment: JDK: OpenJDK Runtime Environment (build 1.8.0_03-Ubuntu-8u77-b03-3ubuntu3-b03)
> OS: Ubuntu 16.04 LTS (Xenial Xerus)
>            Reporter: Jose Tomas Atria
>            Priority: Trivial
>         Attachments: UIMA-4919.patch
>
>
> org.apache.uima.fit.internal.ReflectionUtil.getFields( Class<? extends Resource> clz ) throws a NullPointerException when the given class object represents and interface class on the while test on line 59 because the call to java.lang.Class.getSuperclass() inside the while loop on line 62 returns null as per the [documented behaviour|https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getSuperclass--]: "(getSuperClass()) returns the Class representing the superclass of the entity (class, interface, primitive type or void) represented by this Class. *If this Class represents either the Object class, an interface, a primitive type, or void, then null is returned*.", here:
> {code}
>   public static List<Field> getFields(final Class<?> aClass) {
>     Class<?> cls = aClass;
>     final List<Field> fields = new ArrayList<Field>();
>     while (!cls.equals(Object.class)) { // <- THROWS NPE.
>       final Field[] flds = cls.getDeclaredFields();
>       fields.addAll(Arrays.asList(flds));
>       cls = cls.getSuperclass(); // <- RETURNS NULL
>     }
>     return fields;
>   }
> {code}
> This situation can occur e.g. when doing:
> {code}
> Class<? extends Resource> api = f.getAnnotation( ExternalResource.class ).api();
> ReflectionUtil.getFields( api ) // <- throws NPE if api is an interface, i.e. always.
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)