Skip to content

Issue #234: Using builtin annotation classes before creating a CAS can break type system management#243

Open
reckart wants to merge 5 commits into
mainfrom
bugfix/234-Using-builtin-annotation-classes-before-creating-a-CAS-can-break-type-system-management
Open

Issue #234: Using builtin annotation classes before creating a CAS can break type system management#243
reckart wants to merge 5 commits into
mainfrom
bugfix/234-Using-builtin-annotation-classes-before-creating-a-CAS-can-break-type-system-management

Conversation

@reckart
Copy link
Copy Markdown
Member

@reckart reckart commented Aug 15, 2022

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.
    Only dependencies under approved licenses 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.

…n 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
@reckart reckart added the 🦟 Bug Something isn't working label Aug 15, 2022
@reckart reckart added this to the 3.3.1 milestone Aug 15, 2022
@reckart reckart self-assigned this Aug 15, 2022
@azazali30
Copy link
Copy Markdown

@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

@reckart
Copy link
Copy Markdown
Member Author

reckart commented Aug 31, 2022

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.

@reckart reckart modified the milestones: 3.3.1, 3.3.2 Oct 17, 2022
@reckart
Copy link
Copy Markdown
Member Author

reckart commented Jan 12, 2023

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.

@reckart reckart modified the milestones: 3.3.2, 3.4.1 Feb 7, 2023
@reckart reckart modified the milestones: 3.4.1, 3.4.2 Feb 17, 2023
@reckart reckart modified the milestones: 3.4.2, 3.4.3 Jun 29, 2023
@reckart reckart marked this pull request as draft October 12, 2023 11:46
reckart added a commit that referenced this pull request Sep 23, 2024
@reckart reckart changed the base branch from release/3.3.x to main September 22, 2025 12:08
@reckart reckart modified the milestones: 3.6.1, 3.7.0 Sep 22, 2025
reckart added 2 commits May 25, 2026 12:22
…before-creating-a-CAS-can-break-type-system-management

* main: (1043 commits)
  Issue #444: Improve CasToComparableText
  No issue: Update rulesets
  Issue #444: Improve CasToComparableText
  No issue: Restore basic branch protections
  No issue: Temporarily disable all branch protections - hopefully then I can delete the `rel/441-Apache-UIMA-Java-SDK-3.6.1` branch
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release uimaj-3.6.1
  No issue: Set branch in pom
  Issue #441: Apache UIMA Java SDK 3.6.1
  Issue #441: Apache UIMA Java SDK 3.6.1
  Issue #441: Apache UIMA Java SDK 3.6.1
  Issue #438: Upgrade dependencies (3.6.1)
  No issue: Pull notifications up to root
  Issue #430: Resolving type system imports through sp is slows things down too much
  Issue #435: Improve performance of ImportResolver
  No issue: Try adding unit test report
  Issue #435: Improve performance of ImportResolver
  Issue #435: Improve performance of ImportResolver
  Issue #435: Improve performance of ImportResolver
  Issue #435: Improve performance of ImportResolver
  ...
…n break type system management

- Revert bad fix
- Add proper reproducer test
@reckart reckart requested a review from Copilot May 25, 2026 11:57
@reckart reckart marked this pull request as ready for review May 25, 2026 11:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #234 where loading built-in JCas cover classes (notably Annotation) before any CAS exists can corrupt type system/JCas type-id bookkeeping and prevent feature callsite updates, leading to failures when later creating/using a CAS.

Changes:

  • Adds a regression test that reproduces the problem in a fresh forked JVM and asserts the subprocess exits cleanly.
  • Defers committing TypeSystemImpl.staticTsi from class initialization time to a new lazy committedStaticTsi() accessor to avoid recursive class-init storms.
  • Updates TypeSystemConstants to obtain built-in feature adjusted offsets via TypeSystemImpl.committedStaticTsi().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
uimaj-core/src/test/java/org/apache/uima/jcas/impl/LoadingBuiltinAnnotationBeforeCasTest.java New regression test that forks a fresh JVM to reproduce/guard against issue #234.
uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java Switches static built-in type system commit to lazy-on-demand to prevent recursive initialization issues.
uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemConstants.java Routes built-in feature adjusted-offset constants through the new lazy-commit accessor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java Outdated
Comment thread uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java Outdated
@reckart reckart force-pushed the bugfix/234-Using-builtin-annotation-classes-before-creating-a-CAS-can-break-type-system-management branch from 4c5fa14 to aa308af Compare May 25, 2026 12:44
…n break type system management

- Defer `TypeSystemImpl.staticTsi.commit()` out of `<clinit>` into a new lazy `committedStaticTsi()` accessor with double-checked-locking on a volatile flag, breaking the recursive cover-class init storm that caused the issue
- Route `TypeSystemConstants` builtin-feature `adjOffset` constants through `TypeSystemImpl.committedStaticTsi()` so they remain valid now that `staticTsi` is no longer committed eagerly
@reckart reckart force-pushed the bugfix/234-Using-builtin-annotation-classes-before-creating-a-CAS-can-break-type-system-management branch from aa308af to df242a5 Compare May 25, 2026 12:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread uimaj-core/src/main/java/org/apache/uima/cas/impl/TypeSystemImpl.java Outdated
…n break type system management

- Drop dead `if (staticTsi == null)` guard in `TypeSystemImpl.createCallSiteForBuiltIn` and route the offset lookup through the cached `committedStaticTsi` field (read directly, not via the accessor, to avoid forcing a commit from inside a built-in cover class's `<clinit>` and reintroducing the issue-#234 init storm); fall through to a default callsite when no commit has happened yet
- Replace OS-detection-based `java`/`java.exe` path construction in `LoadingBuiltinAnnotationBeforeCasTest` with `ProcessHandle.current().info().command()` plus a `${java.home}/bin/java` fallback (CreateProcess auto-resolves `.exe` on Windows)
- Drain the forked JVM's output on a daemon thread so the 60s `waitFor` timeout actually fires when the subprocess deadlocks instead of being blocked indefinitely by a synchronous `transferTo`
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🦟 Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants