Uploaded image for project: 'UIMA'
  1. UIMA
  2. UIMA-3560

AnnotationFactory.createAnnotation() should not throw UIMAException

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.1.0uimaFIT
    • uimaFIT
    • None

    Description

      The AnnotationFactory provides a shortcut alternative to creating an annotation and adding it to the indexes:

      JCas/UIMA:

      a) new Token(jcas, 1, 5).addToIndexes();
      b) jcas.addFsToIndexes(jCas.getCas().createAnnotation(JCasUtil.getAnnotationType(jCas, typeClass), begin, end));
      

      AnnotationFactory

      a) createAnnotation(jcas, 1, 5, Token.class);
      b) createAnnotation(jcas, 1, 5, typeClass);
      

      Internally, AnnotationFactory uses reflection on JCas classes to achieve that and if there is a problem while reflectively creating the annotation, it throws an UIMAException. It is very unlikely that a problem would occur. It could happen if security restrictions are in place on certain JCas wrapper classes. Yet, the UIMAException is not a RuntimeException, so it must be caught by client code.

      AnnotationFactory could use the CAS interface instead of reflection to avoid the exception. We can be sure that any annotation created through the CAS interface can safely be cast to a JCas wrapper type, because the JCas has already been initialized when this method is calls (it receives a JCas as argument).

      Attachments

        Activity

          People

            rec Richard Eckart de Castilho
            rec Richard Eckart de Castilho
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: