uima-uimaj icon indicating copy to clipboard operation
uima-uimaj copied to clipboard

Selecting a class from a CAS can yield a classcast exception if the CAS contains subclasses of the type not locally known

Open reckart opened this issue 1 year ago • 0 comments

Describe the bug Let's assume with have a CAS with two types, T and S where S is a subtype of T.

To Reproduce Now let's assume we are in a PEAR that brings along its own version of the T JCas class (let's call it T_p).

When the code in the PEAR does a for var T : select(T.class) (which actually selects T_p and that select returns an S, that leads to a class cast exception because S cannot be cast to T_p.

Expected behavior It would probably be a good idea to add a filter to select(class) to ensure that the values it returns are actually compatible with class - which may in the case of selecting inside a PEAR in the scenario outlined above mean that instances of S are actually not returned.

Please complete the following information:

  • Version: 3.5.0

Additional context Another but similar scenario...

Imagine we have a class outside of the PEAR called H with a field H.x of type X. Now the PEAR brings its own copy of X (i.e. X_p) but not of H. If the pear now calls H.getX() this will return an X instead of an X_p which probably also leads to a class cast exception...

Ok, so the convention is that a PEAR must embed all types it directly uses. Thus, if it wants to call H.getX(), it must embed H which would then be H_p and H_p.getX() would return X_p. So that should be consistent.

reckart avatar Aug 23 '24 14:08 reckart