Wintertree Software Inc.

Sentry Spelling Checker Engine for Java

Home Site index Contact us Catalog Shopping Cart Products Support Search

You are here: Home > Support > Sentry Spelling Checker Engine > Java SDK > SpellingSession.check loops endlessly


SpellingSession.check loops endlessly

Product: Sentry Spelling Checker Engine Java SDK

Problem

SpellingSession.check(WordParser, StringBuffer) sometimes causes an endless loop.

Discussion

SpellingSession.check returns to your application under two circumstances: 1) it finds a problem with a word contained by the WordParser; 2) all the words contained by the WordParser have been checked. The return value from SpellingSession.check indicates the reason for returning. When SpellingSession.check reports a problem with a word (e.g., the word is misspelled), your application must dispose of the problem by either correcting the problem or skipping over the word. If your application doesn't dispose of the problem, SpellingSession.check will report the same word again indefinitely, making it appear to loop.

Example: SpellingSession.check reports a word as misspelled (the return value includes MISSPELLED_WORD_RSLT). If your application doesn't correct the word (by calling WordParser.replaceWord) or skip over the word (by calling WordParser.nextWord), SpellingSession.check will return MISSPELLED_WORD_RSLT again for the same word, over and over.

Solution

Ensure your application is handling each possible spelling check result from SpellingSession.check (see "How to check a single word" in the "Using the Sentry Java SDK" chapter of the programmer's guide for a list of each spelling check result). If your application handles the return value from SpellingSession.check with a series of cascading "else ifs," you may want to add a final "else" to handle any cases not covered, like this:

int spellResult;
while ((spellResult = session.check(parser, otherWord)) != session.END_OF_TEXT_RSLT) {
if ((spellResult & session.MISSPELLED_WORD_RSLT) != 0) {
// dispose of misspelled word by correcting or skipping
}
else if ((spellResult & session.DOUBLED_WORD_RSLT) != 0) {
// dispose of doubled word by deleting or skipping
}
else {
// dipose of other problems by skipping
parser.nextWord();
}
}


Home Site index Contact us Catalog Shopping Cart Products Support Search


Copyright © 2015 Wintertree Software Inc.