When using java maven, detect language requires org.languagetool.language-all

It is not possible to call languageIdentifierService.detectLanguage with only one language setup (e.g.: language-en).

java.lang.NoClassDefFoundError: Could not initialize class org.languagetool.language.identifier.DefaultLanguageIdentifier
at org.languagetool.language.identifier.LanguageIdentifierService.getDefaultLanguageIdentifier([LanguageIdentifierService.java:54](vscode-file://vscode-app/c:/Users/BrunoMarotta/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
...

This happens because CommonWordsDetector requires some hard-coded languages to be loaded by default:

public class CommonWordsDetector {

  private final static Map<String, List<Language>> word2langs = Collections.synchronizedMap(new HashMap<>());
  private final static Pattern numberPattern = Pattern.compile("[0-9.,%-]+");
  
  private final static Language esLang = Languages.getLanguageForShortCode("es");
  private final static Language caLang = Languages.getLanguageForShortCode("ca");
  private final static Language ptLang = Languages.getLanguageForShortCode("pt");

It should be possible to call detectLanguage without having all languages loaded. In this case, detect language should only detect the languages currently loaded.

1 Like