Skip to content

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

Merged
reckart merged 5 commits into
mainfrom
bugfix/234-Using-builtin-annotation-classes-before-creating-a-CAS-can-break-type-system-management
Jun 17, 2026
Merged

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

Conversation

@reckart

@reckart reckart commented Aug 15, 2022

Copy link
Copy Markdown
Member

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.

@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

reckart commented Aug 31, 2022

Copy link
Copy Markdown
Member Author

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

reckart commented Jan 12, 2023

Copy link
Copy Markdown
Member Author

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 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

Copilot AI left a comment

Copy link
Copy Markdown

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 2 times, most recently from aa308af to df242a5 Compare May 25, 2026 12:53
@reckart reckart requested a review from Copilot May 25, 2026 12:53

Copilot AI left a comment

Copy link
Copy Markdown

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
@reckart reckart requested a review from Copilot May 25, 2026 13:18

Copilot AI left a comment

Copy link
Copy Markdown

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.

reckart added 5 commits June 17, 2026 16:40
…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
…n break type system management

- Revert bad fix
- Add proper reproducer test
…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
…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`
…n break type system management

- Fix flaky test FSClassRegistryTest by asserting on specific classloader registration instead of global cache size
- Add test support method isClToType2JCasRegistered() to FSClassRegistry to check classloader registration state
- Remove dependency on process-wide static weak map size which is non-deterministic due to asynchronous GC reaping
@reckart reckart force-pushed the bugfix/234-Using-builtin-annotation-classes-before-creating-a-CAS-can-break-type-system-management branch from e6506db to cbf21b7 Compare June 17, 2026 14:40
@reckart reckart merged commit 9ccde29 into main Jun 17, 2026
5 checks passed
@reckart reckart deleted the bugfix/234-Using-builtin-annotation-classes-before-creating-a-CAS-can-break-type-system-management branch June 17, 2026 15:40
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