You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by Daniel Cosio <dc...@gmail.com> on 2024/09/04 14:35:34 UTC

JCas type not registered in JCasRegistry

Im making progress on my 3.x upgrade. Im now running into this error.

JCas type “my class type" defined in CAS type system and used in Java code, but was not registered in JCasRegistry.

I’ve always had a META-INF/org.apache.uima.fit/types.txt file defining the class paths to the types.. The types are generated with the 3.x version of jcasgen-plugin.

Is there another step to get the type registered?


Daniel Cosio
dccosio@gmail.com




Re: JCas type not registered in JCasRegistry

Posted by Richard Eckart de Castilho <re...@apache.org>.

> On 30. Sep 2024, at 20:02, Daniel Cosio <dc...@gmail.com> wrote:
> 
> No.. this simple test fails
> @Test
> public void testJCas() throws Exception {
> JCas jcas = CasCreationUtils.createCas().getJCas();
> Pair p = new Pair(jcas);
> }
> org.apache.uima.cas.CASRuntimeException: JCas type "org.apache.ctakes.typesystem.type.util.Pair" used in Java code, but was not declared in the XML type descriptor.

Ok, this is perfectly normal. You create a CAS without specifying any type system.

Either you need to specify a type system description to the CasCreationUtils.createCas() or you need to use e.g the JCasFactory.createJCas() from uimaFIT which supports auto-discovery of type system descriptions (see https://uima.apache.org/d/uimafit-current/fit.html#_ugr.tools.uimafit.typesystem).

-- Richard

Re: JCas type not registered in JCasRegistry

Posted by Daniel Cosio <dc...@gmail.com>.
No.. this simple test fails
@Test
public void testJCas() throws Exception {
JCas jcas = CasCreationUtils.createCas().getJCas();
Pair p = new Pair(jcas);
}
org.apache.uima.cas.CASRuntimeException: JCas type "org.apache.ctakes.typesystem.type.util.Pair" used in Java code, but was not declared in the XML type descriptor.

Daniel Cosio
dccosio@gmail.com



> On Sep 30, 2024, at 1:11 PM, Richard Eckart de Castilho <re...@apache.org> wrote:
> 
> Are you using any (custom) JUnit extensions or super-classes to your test classes that may already make calls to UIMA or reference JCas classes?
> 
> -- Richard
> 
>> On 30. Sep 2024, at 18:45, Daniel Cosio <dc...@gmail.com> wrote:
>> 
>> Thanks for getting back to me.. Ya, I did try putting it in a static block.. no luck there.
> 
> 


Re: JCas type not registered in JCasRegistry

Posted by Richard Eckart de Castilho <re...@apache.org>.
Are you using any (custom) JUnit extensions or super-classes to your test classes that may already make calls to UIMA or reference JCas classes?

-- Richard

> On 30. Sep 2024, at 18:45, Daniel Cosio <dc...@gmail.com> wrote:
> 
> Thanks for getting back to me.. Ya, I did try putting it in a static block.. no luck there.



Re: JCas type not registered in JCasRegistry

Posted by Daniel Cosio <dc...@gmail.com>.
Thanks for getting back to me.. Ya, I did try putting it in a static block.. no luck there.

Daniel Cosio
dccosio@gmail.com



> On Sep 30, 2024, at 10:46 AM, Richard Eckart de Castilho <re...@apache.org> wrote:
> 
> Should work in your unit test as well. Maybe you need to call it earlier.
> Have you tried a static block in your unit test class?
> 
> -- Richard
> 
>> On 30. Sep 2024, at 16:34, Daniel Cosio <dc...@gmail.com> wrote:
>> 
>> Any idea why it would work in the application but not in a unit test..
> 
> 


Re: JCas type not registered in JCasRegistry

Posted by Richard Eckart de Castilho <re...@apache.org>.
Should work in your unit test as well. Maybe you need to call it earlier.
Have you tried a static block in your unit test class?

-- Richard

> On 30. Sep 2024, at 16:34, Daniel Cosio <dc...@gmail.com> wrote:
> 
> Any idea why it would work in the application but not in a unit test..



Re: JCas type not registered in JCasRegistry

Posted by Daniel Cosio <dc...@gmail.com>.
Richard,  The fix you suggested worked.. I added CasCreationUtils.createCas()(there is no newJCas()  method as mentioned below.. Im using 3.4.1) and this resolved when running the application..
However, when I run my unit test that fix does not work..

Any idea why it would work in the application but not in a unit test..

Thanks

Daniel Cosio
dccosio@gmail.com



> On Sep 4, 2024, at 10:42 AM, Richard Eckart de Castilho <re...@apache.org> wrote:
> 
> Hi Daniel,
> 
> 
>> On 4. Sep 2024, at 16:35, Daniel Cosio <dc...@gmail.com> wrote:
>> 
>> Im making progress on my 3.x upgrade. Im now running into this error.
>> 
>> JCas type “my class type" defined in CAS type system and used in Java code, but was not registered in JCasRegistry.
>> 
>> I’ve always had a META-INF/org.apache.uima.fit/types.txt file defining the class paths to the types.. The types are generated with the 3.x version of jcasgen-plugin.
>> 
>> Is there another step to get the type registered?
> 
> I suspect you hit this issue:
> 
> https://github.com/apache/uima-uimaj/issues/234
> 
> Try adding a dummy `CasCreationUtils.newJCas()` call when you initialize your application before any UIMA code is called.
> 
> I'm afraid, I have not found a UIMA-side fix for this yet... also not looking at the moment - quite complicated.
> 
> If it is not that issue, let me know.
> 
> Btw. there is also now an SPI-based mechanism to announce types and JCas classes that can be used as an alternative to the `types.txt`.
> 
> https://nightlies.apache.org/uima/draft-guides/fit.html#_using_the_java_service_provide_interface
> https://nightlies.apache.org/uima/draft-guides/user.html#_uv3.spi
> 
> Cheers,
> 
> -- Richard
> 


Re: JCas type not registered in JCasRegistry

Posted by Daniel Cosio <dc...@gmail.com>.
Ah.. ok.. 

Thanks

Daniel Cosio
dccosio@gmail.com



> On Sep 4, 2024, at 10:42 AM, Richard Eckart de Castilho <re...@apache.org> wrote:
> 
> Hi Daniel,
> 
> 
>> On 4. Sep 2024, at 16:35, Daniel Cosio <dc...@gmail.com> wrote:
>> 
>> Im making progress on my 3.x upgrade. Im now running into this error.
>> 
>> JCas type “my class type" defined in CAS type system and used in Java code, but was not registered in JCasRegistry.
>> 
>> I’ve always had a META-INF/org.apache.uima.fit/types.txt file defining the class paths to the types.. The types are generated with the 3.x version of jcasgen-plugin.
>> 
>> Is there another step to get the type registered?
> 
> I suspect you hit this issue:
> 
> https://github.com/apache/uima-uimaj/issues/234
> 
> Try adding a dummy `CasCreationUtils.newJCas()` call when you initialize your application before any UIMA code is called.
> 
> I'm afraid, I have not found a UIMA-side fix for this yet... also not looking at the moment - quite complicated.
> 
> If it is not that issue, let me know.
> 
> Btw. there is also now an SPI-based mechanism to announce types and JCas classes that can be used as an alternative to the `types.txt`.
> 
> https://nightlies.apache.org/uima/draft-guides/fit.html#_using_the_java_service_provide_interface
> https://nightlies.apache.org/uima/draft-guides/user.html#_uv3.spi
> 
> Cheers,
> 
> -- Richard
> 


Re: JCas type not registered in JCasRegistry

Posted by Richard Eckart de Castilho <re...@apache.org>.
Hi Daniel,


> On 4. Sep 2024, at 16:35, Daniel Cosio <dc...@gmail.com> wrote:
> 
> Im making progress on my 3.x upgrade. Im now running into this error.
> 
> JCas type “my class type" defined in CAS type system and used in Java code, but was not registered in JCasRegistry.
> 
> I’ve always had a META-INF/org.apache.uima.fit/types.txt file defining the class paths to the types.. The types are generated with the 3.x version of jcasgen-plugin.
> 
> Is there another step to get the type registered?

I suspect you hit this issue:

https://github.com/apache/uima-uimaj/issues/234

Try adding a dummy `CasCreationUtils.newJCas()` call when you initialize your application before any UIMA code is called.

I'm afraid, I have not found a UIMA-side fix for this yet... also not looking at the moment - quite complicated.

If it is not that issue, let me know.

Btw. there is also now an SPI-based mechanism to announce types and JCas classes that can be used as an alternative to the `types.txt`.

https://nightlies.apache.org/uima/draft-guides/fit.html#_using_the_java_service_provide_interface
https://nightlies.apache.org/uima/draft-guides/user.html#_uv3.spi

Cheers,

-- Richard