The method setCodedText of TextFragment throw exception.

Issue #1109 new
小雨 created an issue

I wanted to set the new codedText to a TextFragment by using the setCodedText method.

The codedText in the TextFragment was some string like this "\uE103\uE110 abc \uE103\uE111 bcd" and the codes in TextFragment were [{id:1, tagType:PLACEHOLDER}, {id:2, tagType:PLACEHOLDER }].

The new codedText was some string like this " abc \uE103\uE111 bcd".

When I set the new codedText, I got the exception  InvalidContentException  "Markers in coded text...". It means I miss some codeMark in the codedText according to the code list.

Then I tried the setCodedText(codedText, allowCodeDeletion) method to update the TextFragment. This time there was no exception and the missing codes in the TextFragment was deleted. But I got the codes array index out of range exception, when I used the getCodedText method of the updated TextFragment. I found the codeMark in the codedText was not sync to the new code list. That might cause the index out of range problem.

As a result, I had no way to set a codedText with missing codeMark to a exist TextFragment. Is there any way to do this? Or I need to correct the codeMark in codedText with the code list myself?

Comments (2)

  1. jhargrave-straker

    Can you help me create a unit test for this? Currently I have this test (which passes), but I’m not sure I am recreating the steps accurately in your description:

    @Test
        public void testIssue1109() {
            TextFragment frag = new TextFragment();
            frag.append(TagType.PLACEHOLDER, "", "", 1);
            frag.append(" abc ");
            frag.append(TagType.PLACEHOLDER, "", "", 2);
            frag.append(" bcd");
            assertEquals("\uE103\uE110 abc \uE103\uE111 bcd", frag.getCodedText());
            TextFragment frag2 = new TextFragment();
            frag2.setCodedText(frag.toString());
            assertEquals("\uE103\uE110 abc \uE103\uE111 bcd", frag2.getCodedText());
        }
    

  2. Log in to comment