Skip to content

Commit

Permalink
This fix the IndexOutOfBounds error
Browse files Browse the repository at this point in the history
Closes #9852
  • Loading branch information
abimaelrsergio authored and danielnaber committed May 1, 2024
1 parent 9737e93 commit 2407af1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,11 @@ protected final List<SentenceData> computeSentenceData(List<AnalyzedSentence> an
int lineCount = 0;
int columnCount = 1;
List<SentenceData> result = new ArrayList<>(texts.size());

if (analyzedSentences == null || analyzedSentences.isEmpty()) {
return result;
}

for (int i = 0; i < texts.size(); i++) {
String sentence = texts.get(i);
result.add(new SentenceData(analyzedSentences.get(i), sentence, charCount, lineCount, columnCount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,47 @@

public class JLanguageToolTest {

private final Language LANG = Languages.getLanguageForShortCode("xx");

@Test
public void testUserConfig() throws IOException {
Language lang = Languages.getLanguageForShortCode("xx");
JLanguageTool lt1 = new JLanguageTool(lang);
JLanguageTool lt1 = new JLanguageTool(LANG);
lt1.disableRule("test_unification_with_negation");
List<RuleMatch> matches1 = lt1.check("This is my test");
assertThat(matches1.size(), is(0));

List<Rule> userRules = new ArrayList<>();
List<PatternToken> patternTokens = Arrays.asList(PatternRuleBuilderHelper.token("my"), PatternRuleBuilderHelper.token("test"));
userRules.add(new PatternRule("MY_TEST", lang, patternTokens, "test rule desc", "my test rule", "my test rule"));
userRules.add(new PatternRule("MY_TEST", LANG, patternTokens, "test rule desc", "my test rule", "my test rule"));
Map<String, Object[]> map = new HashMap<>();
UserConfig userConfig = new UserConfig(Collections.emptyList(), userRules, map, -1, 1L, "fake", null, null, false, null, null, false, null);
JLanguageTool lt2 = new JLanguageTool(lang, null, userConfig);
JLanguageTool lt2 = new JLanguageTool(LANG, null, userConfig);
lt2.disableRule("test_unification_with_negation");
List<RuleMatch> matches2 = lt2.check("This is my test");
assertThat(matches2.size(), is(1));
}

@Test
public void testCheckString() throws IOException {
JLanguageTool jLanguageTool = new JLanguageTool(LANG);
List<RuleMatch> ruleMatches = jLanguageTool.check("This is my test.");
assertThat(ruleMatches.size(), is(1));
}

@Test
public void testCheckStringWithCallbackReturnsTrue() throws IOException {
JLanguageTool jLanguageTool = new JLanguageTool(LANG);
jLanguageTool.setCheckCancelledCallback(() -> true);
List<RuleMatch> ruleMatches = jLanguageTool.check("This is my test.");
assertThat(ruleMatches.size(), is(0));
}

@Test
public void testCheckStringWithCallbackReturnsFalse() throws IOException {
JLanguageTool jLanguageTool = new JLanguageTool(LANG);
jLanguageTool.setCheckCancelledCallback(() -> false);
List<RuleMatch> ruleMatches = jLanguageTool.check("This is my test.");
assertThat(ruleMatches.size(), is(1));
}

}

0 comments on commit 2407af1

Please sign in to comment.