Jose Tomas Atria created UIMA-4919:
--------------------------------------
Summary: 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
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
java.lang.Class.getSuperclass() call 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)