languagetool-org/languagetool · error · RuntimeException

Language was already instantiated, see the cause stacktrace

Error message

Language was already instantiated, see the cause stacktrace below.

What it means

French's public no-arg constructor is deprecated precisely to throw: it forbids direct construction because French must be a singleton (accessed via getInstance()). The first instantiation records a stack trace; any subsequent one throws RuntimeException with that trace as cause.

Source

Thrown at languagetool-language-modules/fr/src/main/java/org/languagetool/language/French.java:84

  private static final Pattern TYPOGRAPHY_PATTERN_13 = compile("\u00a0 ");
  private static final Pattern TYPOGRAPHY_PATTERN_14 = compile(" \u00a0");
  private static final Pattern TYPOGRAPHY_PATTERN_15 = compile(" \u202f");
  private static final Pattern TYPOGRAPHY_PATTERN_16 = compile("\u202f ");

  private static final String FRENCH_SHORT_CODE = "fr";

  private static volatile Throwable instantiationTrace;

  /**
   * @deprecated don't use this method besides the inheritance or core code. Languages are not supposed to be
   * instantiated multiple times. They may contain heavy data which may waste the memory.
   * Use {@link #getInstance()} instead.
   */
  @Deprecated
  public French() {
    Throwable trace = instantiationTrace;
    if (trace != null) {
      throw new RuntimeException("Language was already instantiated, see the cause stacktrace below.", trace);
    }
    instantiationTrace = new Throwable();
  }

  /**
   * This is a fake constructor overload for the subclasses. Public constructors can only be used by the LT itself.
   */
  protected French(boolean fakeValue) {
  }

  @Override
  public SentenceTokenizer createDefaultSentenceTokenizer() {
    return new SRXSentenceTokenizer(this);
  }

  @Override
  public String getName() {
    return "French";

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Replace new French() with French.getInstance() or Languages.getLanguageForShortCode("fr").
  2. Migrate off the deprecated constructor entirely — it is designed to fail on duplicate use.
  3. Check the embedded cause trace to find the earlier instantiation and remove it.

Example fix

// before
French french = new French();
// after
French french = French.getInstance();
Defensive patterns

Strategy: validation

Validate before calling

// Obtain the singleton instead of the deprecated constructor:
French french = French.getInstance(); // or Languages.getLanguageForShortCode("fr")

Try / catch

try {
  new French();
} catch (RuntimeException e) {
  e.getCause().printStackTrace(); // first instantiation site
}

Prevention

When it happens

Trigger: Calling new French() (the deprecated constructor) more than once — or after the singleton was created via getInstance()/Languages registry.

Common situations: Legacy code still using the deprecated constructor after an LT upgrade introduced the guard; tutorials/copied snippets instantiating French directly; frameworks reflectively calling no-arg constructors.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/3cc4bf57dd85becc. Report an issue: GitHub.