You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2022/08/15 19:29:14 UTC

[uima-uimaj] 01/01: Issue #234: Using builtin annotation classes before creating a CAS can break type system management

This is an automated email from the ASF dual-hosted git repository.

rec pushed a commit to branch bugfix/234-Using-builtin-annotation-classes-before-creating-a-CAS-can-break-type-system-management
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git

commit d7e10a4cfacf84b1d4f3a4440cea2d435cb08b2f
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Mon Aug 15 21:29:08 2022 +0200

    Issue #234: Using builtin annotation classes before creating a CAS can break type system management
    
    - Try fixing the case if a JCCI was created with a bad type ID because the type ID had not been set yet
---
 .../java/org/apache/uima/cas/impl/FSClassRegistry.java     | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
index ee9824313..7db860c28 100644
--- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
+++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSClassRegistry.java
@@ -620,6 +620,20 @@ public abstract class FSClassRegistry { // abstract to prevent instantiating; th
       jcci = maybeCreateJCasClassInfo(ti, cl, type2jcci, lookup);
     }
 
+    // Due to initialization order, it could be that we created the JCCI before the static fields in
+    // the JCas class have been initialized. In particular, the jcasType typeIndexID might still
+    // have been uninitialized (0) when we crated the JCCI. To work fix that case, check if the
+    // typeIndexID has changed and if so update the JCCI
+    if (jcci != null && jcci.jcasType == 0) {
+      if (!Modifier.isAbstract(jcci.jcasClass.getModifiers())) { // skip next for abstract classes
+        int jcasType = Misc.getStaticIntFieldNoInherit(jcci.jcasClass, "typeIndexID");
+        if (jcasType != jcci.jcasType) {
+          jcci = new JCasClassInfo(jcci.jcasClass, jcci.generator, jcasType);
+          type2jcci.put(ti.getJCasClassName(), jcci);
+        }
+      }
+    }
+
     // do this setup for new type systems using previously loaded jcci, as well as
     // for new jccis
     if (jcci != null && jcci.jcasType >= 0) {