uima-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marshall Schor (JIRA)" <...@uima.apache.org>
Subject [jira] [Commented] (UIMA-5554) Strange exception when trying to get JCas FS class through reflection
Date Fri, 08 Sep 2017 21:27:05 GMT

    [ https://issues.apache.org/jira/browse/UIMA-5554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16159372#comment-16159372
] 

Marshall Schor commented on UIMA-5554:
--------------------------------------

It's not harmful, but there's an "ordering" issue, due to JCas static initializer code.  This
can be solved in 2 ways.

Class.forName has 2 flavors.  The "plain" flavor loads the class *and initializes* it. That
is, it runs the static initializers among other things.

In UIMA V3, these initializers reference information about the type system that defines the
corresponding UIMA Type for this JCas classes.  Therefore, these types need to be "installed"
- that is committed :-), before the class initialization happens.

So, you can do a Class.forName("myJCasClassName", false, this.getClass().getClassLoader()),
which skips the initialization (the *false* argument says to not do the initialization.  The
initialization will happen on first use, at which time the type system must be committed.

The other way to get Class.forname("myJCasClassName") (the plain variation) to work is to
first commit a type system that defines the type this JCas class is covering.  

I hope that's clear; if not, please ask more questions.

> Strange exception when trying to get JCas FS class through reflection
> ---------------------------------------------------------------------
>
>                 Key: UIMA-5554
>                 URL: https://issues.apache.org/jira/browse/UIMA-5554
>             Project: UIMA
>          Issue Type: Bug
>          Components: Core Java Framework
>    Affects Versions: 3.0.0SDK-beta
>            Reporter: Richard Eckart de Castilho
>
> I am trying to get a class object for a JCas FS type using reflection:
> {noformat}
> Class.forName(typeName);
> {noformat}
> However, it produces this strange error.
> {noformat}
> java.lang.ExceptionInInitializerError
> 	at java.lang.Class.forName0(Native Method)
> 	at java.lang.Class.forName(Class.java:264)
> ...
> Caused by: org.apache.uima.cas.CASRuntimeException: A JCas class field "sofa" is being
initialized by non-framework (user) code before Type System Commit for a type system with
a corresponding type. Either change the user load code to not do initialize, or to defer it
until after the type system commit.
> 	at org.apache.uima.cas.impl.TypeSystemImpl.getAdjustedFeatureOffset(TypeSystemImpl.java:2575)
> 	at org.apache.uima.jcas.cas.AnnotationBase.<clinit>(AnnotationBase.java:71)
> 	... 27 more
> {noformat}
> Is it considered harmful to try getting a class object for a JCas FS class?



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message