You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by GitBox <gi...@apache.org> on 2022/08/15 19:30:41 UTC

[GitHub] [uima-uimaj] reckart opened a new pull request, #243: Issue #234: Using builtin annotation classes before creating a CAS can break type system management

reckart opened a new pull request, #243:
URL: https://github.com/apache/uima-uimaj/pull/243

   **What's in the PR**
   - Try fixing the case if a JCCI was created with a bad type ID because the type ID had not been set yet
   
   **How to test manually**
   * Try running the ClearTK `TimeMlAnnotateTest` _caugh_
   
   **Automatic testing**
   * [ ] PR adds/updates unit tests
   
   **Documentation**
   * [ ] PR adds/updates documentation
   
   **Organizational**
   - [ ] PR adds/updates dependencies.
         <sub><sup>Only dependencies under [approved licenses](http://www.apache.org/legal/resolved.html#category-a) are allowed. LICENSE and NOTICE files in the respective modules where dependencies have been added as well as in the project root have been updated.</sup></sub>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@uima.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [uima-uimaj] azazali30 commented on pull request #243: Issue #234: Using builtin annotation classes before creating a CAS can break type system management

Posted by GitBox <gi...@apache.org>.
azazali30 commented on PR #243:
URL: https://github.com/apache/uima-uimaj/pull/243#issuecomment-1232653269

   @reckart  are we merging this fix, we are waiting for this fix to merge so that we can proceed with [refactoring/442-Upgrade-to-UIMAv3](https://github.com/ClearTK/cleartk/pull/443)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@uima.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [uima-uimaj] reckart commented on pull request #243: Issue #234: Using builtin annotation classes before creating a CAS can break type system management

Posted by GitBox <gi...@apache.org>.
reckart commented on PR #243:
URL: https://github.com/apache/uima-uimaj/pull/243#issuecomment-1380172921

   The work in this branch so far is unable to fix the problem.
   
   The recommended workaround is to create a CAS object before working with any JCas classes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@uima.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [uima-uimaj] reckart commented on pull request #243: Issue #234: Using builtin annotation classes before creating a CAS can break type system management

Posted by GitBox <gi...@apache.org>.
reckart commented on PR #243:
URL: https://github.com/apache/uima-uimaj/pull/243#issuecomment-1232655323

   There is no fix yet - I need to find time to investigate it further because changes in this PR do not yet resolve the problem.
   
   The alternative would be a workaround. I think it might be sufficient to create a dummy CAS before the failing tests accesses the JCas classes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@uima.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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

Posted by "reckart (via GitHub)" <gi...@apache.org>.
reckart merged PR #243:
URL: https://github.com/apache/uima-uimaj/pull/243


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@uima.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #243:
URL: https://github.com/apache/uima-uimaj/pull/243#discussion_r3298036767


##########
uimaj-core/src/test/java/org/apache/uima/jcas/impl/LoadingBuiltinAnnotationBeforeCasTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.jcas.impl;
+
+import static java.lang.System.getProperty;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
+import org.apache.uima.util.CasCreationUtils;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Reproduces <a href="https://github.com/apache/uima-uimaj/issues/234">issue #234</a>: when a
+ * built-in Annotation cover class is touched before any CAS exists, the type system records a wrong
+ * (zero) jcasType for it and Annotation's feature callsites are never updated. Subsequent
+ * {@code getCasType} / {@code setBegin} calls then fail.
+ *
+ * <p>
+ * The bug only manifests in a fresh JVM where nothing has yet initialized {@link Annotation}. Class
+ * initialization is once-per-JVM, so running this in the shared Surefire JVM (where other tests
+ * have already created CASes and thereby initialized Annotation normally) would not reproduce it.
+ * The test therefore forks a dedicated JVM running {@link #main(String[])} and asserts on its exit
+ * code.
+ */
+public class LoadingBuiltinAnnotationBeforeCasTest {
+
+  /**
+   * Reproducer body. Must run in a fresh JVM (see the {@code @Test} below). Throws on failure so
+   * the JVM exits non-zero.
+   */
+  public static void main(String[] args) throws Exception {
+    // Force Annotation's <clinit> to start now, before any TypeSystemImpl / CAS exists.
+    // Annotation's super (AnnotationBase) references TypeSystemImpl in its own <clinit>, which
+    // kicks off a recursive init storm that reads Annotation.typeIndexID while it's still 0 --
+    // caching a broken JCasClassInfo and skipping Annotation's _FC_begin / _FC_end callsite update.
+    Class.forName(Annotation.class.getName());
+
+    var tsd = new TypeSystemDescription_impl();
+    var jcas = CasCreationUtils.createCas(tsd, null, null).getJCas();
+
+    // (1) Type system lookup by JCas type id. With the bug, slot Annotation.type of
+    // jcasRegisteredTypes is empty (the JCCI got registered at slot 0 instead).
+    jcas.getCasType(Annotation.type);
+
+    // (2) setDocumentText eventually calls Annotation.setBegin, which dispatches through the
+    // _FC_begin callsite. With the bug, that callsite still returns -1 and the offset lookup
+    // throws ArrayIndexOutOfBoundsException.
+    jcas.setDocumentText("hello");
+  }
+
+  @Test
+  void thatLoadingAnnotationBeforeCasDoesNotBreakTypeSystemManagement() throws Exception {
+    var windows = getProperty("os.name").toLowerCase().contains("win");
+    var java = getProperty("java.home") + File.separator + "bin" + File.separator
+            + (windows ? "java.exe" : "java");
+
+    var pb = new ProcessBuilder(java, "-cp", getProperty("java.class.path"), getClass().getName());
+    pb.redirectErrorStream(true);
+    var p = pb.start();
+
+    var buf = new ByteArrayOutputStream();
+    p.getInputStream().transferTo(buf);
+    int exit = p.waitFor();
+

Review Comment:
   The test waits for the forked JVM using `p.waitFor()` with no timeout. If the subprocess deadlocks or hangs (which is plausible for class-init regression tests), the build can hang indefinitely.
   
   Consider using `waitFor(timeout, unit)` and failing the test if the subprocess does not exit within a reasonable time, optionally destroying the process.



##########
uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java:
##########
@@ -2867,11 +2865,34 @@ public List<TypeImpl> getAllTypes() {
   }
 
   public static final TypeSystemImpl staticTsi = new TypeSystemImpl();
-  static {
-    TypeSystemImpl tsi = staticTsi.commit(); // needed to assign adjusted offsets to the builtins
-    if (tsi != staticTsi) {
-      Misc.internalError();
+
+  // staticTsi was previously committed inside this class's <clinit>. That triggered a recursive
+  // load-cover-classes storm: a built-in JCas cover class's <clinit> could be the very thing that
+  // caused TypeSystemImpl to load (e.g. via createCallSiteForBuiltIn). The commit then asked the
+  // JVM to fully initialize that same cover class while it was still mid-init on the current
+  // thread, producing a zero/default typeIndexID and broken callsites (issue #234). Commit is now
+  // deferred until first real demand via committedStaticTsi().
+  private static volatile boolean staticTsiCommitted;
+
+  /**
+   * Returns {@link #staticTsi} after ensuring it has been committed. Commit is performed lazily and
+   * exactly once across all threads. Code that needs commit-dependent state on staticTsi (e.g.
+   * {@link TypeImpl#getAdjOffset(String)}) must go through this accessor rather than
+   * {@link #staticTsi} directly.
+   */
+  public static TypeSystemImpl committedStaticTsi() {
+    if (!staticTsiCommitted) {
+      synchronized (TypeSystemImpl.class) {
+        if (!staticTsiCommitted) {
+          TypeSystemImpl tsi = staticTsi.commit();
+          if (tsi != staticTsi) {
+            Misc.internalError();
+          }
+          staticTsiCommitted = true;
+        }
+      }
     }
+    return staticTsi;

Review Comment:
   `committedStaticTsi()` assumes `staticTsi.commit()` always returns `staticTsi` and calls `Misc.internalError()` otherwise. With commit now deferred, it becomes possible for another equal `TypeSystemImpl` instance (e.g. created via `CASFactory.createTypeSystem()` and committed first) to enter the `committedTypeSystems` consolidation map before `staticTsi` is committed, in which case `staticTsi.commit()` may legally return the already-committed consolidated instance (not `staticTsi`) and this code will hard-fail.
   
   Consider adjusting this accessor to tolerate consolidation (e.g. store and return the actual committed instance from `staticTsi.commit()`), or otherwise ensure `staticTsi` is committed before any other equivalent type system can be committed.
   



##########
uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java:
##########
@@ -2130,9 +2130,7 @@ public int getFeatureOffset(TypeImpl ti, String featureShortName) {
   // TypeInfo getTypeInfo(int typeCode) {
   // if (null == typeInfoArray[typeCode]) {
   // TypeImpl type = (TypeImpl) ll_getTypeForCode(typeCode);
-  //// if (null == type) {
-  //// diagnoseBadTypeCode(typeCode);
-  //// }
+  //// if (null == type) { / diagnoseBadTypeCode(typeCode); / }

Review Comment:
   This commented-out line was reformatted into a single line with inline `/ ... /` markers: `//// if (null == type) { / diagnoseBadTypeCode(typeCode); / }`. As written, it’s difficult to read and looks like accidental corruption of the original commented code.
   
   Consider restoring the original multi-line commented block (or removing it entirely if it’s no longer needed) to keep the history readable.
   



##########
uimaj-core/src/test/java/org/apache/uima/jcas/impl/LoadingBuiltinAnnotationBeforeCasTest.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.jcas.impl;
+
+import static java.lang.System.getProperty;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
+import org.apache.uima.util.CasCreationUtils;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Reproduces <a href="https://github.com/apache/uima-uimaj/issues/234">issue #234</a>: when a
+ * built-in Annotation cover class is touched before any CAS exists, the type system records a wrong
+ * (zero) jcasType for it and Annotation's feature callsites are never updated. Subsequent
+ * {@code getCasType} / {@code setBegin} calls then fail.
+ *
+ * <p>
+ * The bug only manifests in a fresh JVM where nothing has yet initialized {@link Annotation}. Class
+ * initialization is once-per-JVM, so running this in the shared Surefire JVM (where other tests
+ * have already created CASes and thereby initialized Annotation normally) would not reproduce it.
+ * The test therefore forks a dedicated JVM running {@link #main(String[])} and asserts on its exit
+ * code.
+ */
+public class LoadingBuiltinAnnotationBeforeCasTest {
+
+  /**
+   * Reproducer body. Must run in a fresh JVM (see the {@code @Test} below). Throws on failure so
+   * the JVM exits non-zero.
+   */
+  public static void main(String[] args) throws Exception {
+    // Force Annotation's <clinit> to start now, before any TypeSystemImpl / CAS exists.
+    // Annotation's super (AnnotationBase) references TypeSystemImpl in its own <clinit>, which
+    // kicks off a recursive init storm that reads Annotation.typeIndexID while it's still 0 --
+    // caching a broken JCasClassInfo and skipping Annotation's _FC_begin / _FC_end callsite update.
+    Class.forName(Annotation.class.getName());
+
+    var tsd = new TypeSystemDescription_impl();
+    var jcas = CasCreationUtils.createCas(tsd, null, null).getJCas();
+
+    // (1) Type system lookup by JCas type id. With the bug, slot Annotation.type of
+    // jcasRegisteredTypes is empty (the JCCI got registered at slot 0 instead).
+    jcas.getCasType(Annotation.type);
+
+    // (2) setDocumentText eventually calls Annotation.setBegin, which dispatches through the
+    // _FC_begin callsite. With the bug, that callsite still returns -1 and the offset lookup
+    // throws ArrayIndexOutOfBoundsException.
+    jcas.setDocumentText("hello");
+  }
+
+  @Test
+  void thatLoadingAnnotationBeforeCasDoesNotBreakTypeSystemManagement() throws Exception {
+    var windows = getProperty("os.name").toLowerCase().contains("win");
+    var java = getProperty("java.home") + File.separator + "bin" + File.separator
+            + (windows ? "java.exe" : "java");
+
+    var pb = new ProcessBuilder(java, "-cp", getProperty("java.class.path"), getClass().getName());
+    pb.redirectErrorStream(true);
+    var p = pb.start();
+
+    var buf = new ByteArrayOutputStream();
+    p.getInputStream().transferTo(buf);
+    int exit = p.waitFor();
+
+    assertThat(exit).as("forked JVM exited non-zero; subprocess output was:%n%s", buf.toString())
+            .isZero();

Review Comment:
   `buf.toString()` uses the platform default charset, which can make the failure message inconsistent across environments. Consider decoding the subprocess output with an explicit charset (e.g. UTF-8) when formatting the assertion message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@uima.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #243:
URL: https://github.com/apache/uima-uimaj/pull/243#discussion_r3298270124


##########
uimaj-core/src/test/java/org/apache/uima/jcas/impl/LoadingBuiltinAnnotationBeforeCasTest.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.jcas.impl;
+
+import static java.lang.System.getProperty;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
+import org.apache.uima.util.CasCreationUtils;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Reproduces <a href="https://github.com/apache/uima-uimaj/issues/234">issue #234</a>: when a
+ * built-in Annotation cover class is touched before any CAS exists, the type system records a wrong
+ * (zero) jcasType for it and Annotation's feature callsites are never updated. Subsequent
+ * {@code getCasType} / {@code setBegin} calls then fail.
+ *
+ * <p>
+ * The bug only manifests in a fresh JVM where nothing has yet initialized {@link Annotation}. Class
+ * initialization is once-per-JVM, so running this in the shared Surefire JVM (where other tests
+ * have already created CASes and thereby initialized Annotation normally) would not reproduce it.
+ * The test therefore forks a dedicated JVM running {@link #main(String[])} and asserts on its exit
+ * code.
+ */
+public class LoadingBuiltinAnnotationBeforeCasTest {
+
+  /**
+   * Reproducer body. Must run in a fresh JVM (see the {@code @Test} below). Throws on failure so
+   * the JVM exits non-zero.
+   */
+  public static void main(String[] args) throws Exception {
+    // Force Annotation's <clinit> to start now, before any TypeSystemImpl / CAS exists.
+    // Annotation's super (AnnotationBase) references TypeSystemImpl in its own <clinit>, which
+    // kicks off a recursive init storm that reads Annotation.typeIndexID while it's still 0 --
+    // caching a broken JCasClassInfo and skipping Annotation's _FC_begin / _FC_end callsite update.
+    Class.forName(Annotation.class.getName());
+
+    var tsd = new TypeSystemDescription_impl();
+    var jcas = CasCreationUtils.createCas(tsd, null, null).getJCas();
+
+    // (1) Type system lookup by JCas type id. With the bug, slot Annotation.type of
+    // jcasRegisteredTypes is empty (the JCCI got registered at slot 0 instead).
+    jcas.getCasType(Annotation.type);
+
+    // (2) setDocumentText eventually calls Annotation.setBegin, which dispatches through the
+    // _FC_begin callsite. With the bug, that callsite still returns -1 and the offset lookup
+    // throws ArrayIndexOutOfBoundsException.
+    jcas.setDocumentText("hello");
+  }
+
+  @Test
+  void thatLoadingAnnotationBeforeCasDoesNotBreakTypeSystemManagement() throws Exception {
+    var windows = getProperty("os.name").toLowerCase().contains("win");
+    var java = getProperty("java.home") + File.separator + "bin" + File.separator
+            + (windows ? "java.exe" : "java");
+
+    var pb = new ProcessBuilder(java, "-cp", getProperty("java.class.path"), getClass().getName());
+    pb.redirectErrorStream(true);
+    var p = pb.start();
+
+    var buf = new ByteArrayOutputStream();
+    p.getInputStream().transferTo(buf);
+
+    // Bound the wait so a hypothetical class-init deadlock in the subprocess can't hang CI.
+    if (!p.waitFor(60, TimeUnit.SECONDS)) {

Review Comment:
   `p.getInputStream().transferTo(buf)` is executed before the timed `waitFor`. Since `transferTo` blocks until EOF, a deadlocked/hung subprocess will block here indefinitely and the 60s timeout will never be reached. Consider consuming the subprocess output asynchronously (e.g., a separate thread) or waiting with a timeout first and only then reading the completed output (or redirecting output to a file) so the test cannot hang CI.



##########
uimaj-core/src/test/java/org/apache/uima/jcas/impl/LoadingBuiltinAnnotationBeforeCasTest.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.jcas.impl;
+
+import static java.lang.System.getProperty;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
+import org.apache.uima.util.CasCreationUtils;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Reproduces <a href="https://github.com/apache/uima-uimaj/issues/234">issue #234</a>: when a
+ * built-in Annotation cover class is touched before any CAS exists, the type system records a wrong
+ * (zero) jcasType for it and Annotation's feature callsites are never updated. Subsequent
+ * {@code getCasType} / {@code setBegin} calls then fail.
+ *
+ * <p>
+ * The bug only manifests in a fresh JVM where nothing has yet initialized {@link Annotation}. Class
+ * initialization is once-per-JVM, so running this in the shared Surefire JVM (where other tests
+ * have already created CASes and thereby initialized Annotation normally) would not reproduce it.
+ * The test therefore forks a dedicated JVM running {@link #main(String[])} and asserts on its exit
+ * code.
+ */
+public class LoadingBuiltinAnnotationBeforeCasTest {
+
+  /**
+   * Reproducer body. Must run in a fresh JVM (see the {@code @Test} below). Throws on failure so
+   * the JVM exits non-zero.
+   */
+  public static void main(String[] args) throws Exception {
+    // Force Annotation's <clinit> to start now, before any TypeSystemImpl / CAS exists.
+    // Annotation's super (AnnotationBase) references TypeSystemImpl in its own <clinit>, which
+    // kicks off a recursive init storm that reads Annotation.typeIndexID while it's still 0 --
+    // caching a broken JCasClassInfo and skipping Annotation's _FC_begin / _FC_end callsite update.
+    Class.forName(Annotation.class.getName());
+
+    var tsd = new TypeSystemDescription_impl();
+    var jcas = CasCreationUtils.createCas(tsd, null, null).getJCas();
+
+    // (1) Type system lookup by JCas type id. With the bug, slot Annotation.type of
+    // jcasRegisteredTypes is empty (the JCCI got registered at slot 0 instead).
+    jcas.getCasType(Annotation.type);
+
+    // (2) setDocumentText eventually calls Annotation.setBegin, which dispatches through the
+    // _FC_begin callsite. With the bug, that callsite still returns -1 and the offset lookup
+    // throws ArrayIndexOutOfBoundsException.
+    jcas.setDocumentText("hello");
+  }
+
+  @Test
+  void thatLoadingAnnotationBeforeCasDoesNotBreakTypeSystemManagement() throws Exception {
+    var windows = getProperty("os.name").toLowerCase().contains("win");

Review Comment:
   Windows detection via `os.name.toLowerCase().contains("win")` can mis-detect non-Windows OS names containing "win" (e.g. "Darwin"). Use a stricter check such as `startsWith("windows")` (or similar) to avoid building a non-existent `java.exe` path.
   



##########
uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java:
##########
@@ -2867,11 +2867,40 @@ public List<TypeImpl> getAllTypes() {
   }
 
   public static final TypeSystemImpl staticTsi = new TypeSystemImpl();
-  static {
-    TypeSystemImpl tsi = staticTsi.commit(); // needed to assign adjusted offsets to the builtins
-    if (tsi != staticTsi) {
-      Misc.internalError();
+
+  // staticTsi was previously committed inside this class's <clinit>. That triggered a recursive
+  // load-cover-classes storm: a built-in JCas cover class's <clinit> could be the very thing that
+  // caused TypeSystemImpl to load (e.g. via createCallSiteForBuiltIn). The commit then asked the
+  // JVM to fully initialize that same cover class while it was still mid-init on the current
+  // thread, producing a zero/default typeIndexID and broken callsites (issue #234). Commit is now
+  // deferred until first real demand via committedStaticTsi().
+  //
+  // Note: under deferred commit, another TypeSystemImpl with the same builtin-only structure may
+  // be committed before staticTsi is. In that case staticTsi.commit() consolidates to that other
+  // instance via committedTypeSystems (and staticTsi itself stays unfinalized). We therefore cache
+  // and return whatever commit() returns -- that is the instance with the correctly computed
+  // offsets.
+  private static volatile TypeSystemImpl committedStaticTsi;
+
+  /**
+   * Returns a committed builtin-only {@link TypeSystemImpl} -- either {@link #staticTsi} itself if
+   * it was the first one to commit, or whatever structurally-equivalent committed instance it was
+   * consolidated to. Commit is performed lazily and exactly once across all threads. Code that
+   * needs commit-dependent state (e.g. {@link TypeImpl#getAdjOffset(String)}) must go through this
+   * accessor rather than reading {@link #staticTsi} directly.
+   */
+  public static TypeSystemImpl committedStaticTsi() {
+    TypeSystemImpl result = committedStaticTsi;
+    if (result == null) {
+      synchronized (TypeSystemImpl.class) {
+        result = committedStaticTsi;
+        if (result == null) {
+          result = staticTsi.commit();
+          committedStaticTsi = result;

Review Comment:
   The new lazy-commit design explicitly allows `staticTsi.commit()` to consolidate to a different committed instance, leaving `staticTsi` itself unfinalized. However, other code (notably `createCallSiteForBuiltIn(...)`) still uses `staticTsi` directly to read `jcasRegisteredTypes` and compute `TypeImpl#getAdjOffset`, which can yield `null`/`-1` and leave builtin call sites permanently incorrect when the commit already happened on a different instance. Consider updating builtin callsite creation to use the already-committed instance (`committedStaticTsi` if non-null) for offset lookups, and avoid forcing a commit during cover-class initialization; also, the existing `if (staticTsi == null)` guard in `createCallSiteForBuiltIn` is ineffective since `staticTsi` is `static final`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@uima.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org