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

Inconsistent behavior on going beyond index limits in SelectFS

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.0SDK
    • 3.0.1SDK
    • Core Java Framework
    • None

    Description

      The behavior of trying to address annotations outside the index appears to be inconsistent.

      For example, the following call returns `null`:

          String text = "one two three";
          tokenBuilder.buildTokens(jCas, text);
      
          List<Token> tokens = new ArrayList<Token>(select(jCas, Token.class));
          
          for (Token token : tokens) {
            new AnalyzedText(jCas, token.getBegin(), token.getEnd()).addToIndexes();
          }    
          
          Token firstToken = tokens.get(0);
      
          AnalyzedText x = jCas.select(AnalyzedText.class).preceding(firstToken, 0).get();
      

      However, this code trying go from the end of the index to before the first item throws a CASRuntime exception:

          String text = "Rot wood cheeses dew?";
          tokenBuilder.buildTokens(jCas, text);
      
          assertThatExceptionOfType(CASRuntimeException.class)
              .isThrownBy(() -> jCas.select(Token.class).backwards().get(4))
              .withMessage("CAS does not contain any '" + Token.class.getName() + "' instances  shifted by: 4.");
      

      It would seem reasonably to either always return null or to always thrown an exception. If an exception is thrown, it would seem reasonable to introduce a subtype of the CASRuntimeException, e.g. a CASIndexOutOfBounds exception or something the likes. CASRuntimeException seems very general.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: