{"record":{"id":"3cc4bf57dd85becc","repo":"languagetool-org/languagetool","slug":"language-was-already-instantiated-see-the-cause-s-3cc4bf","errorCode":null,"errorMessage":"Language was already instantiated, see the cause stacktrace below.","messagePattern":"Language was already instantiated, see the cause stacktrace below\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-language-modules/fr/src/main/java/org/languagetool/language/French.java","lineNumber":84,"sourceCode":"  private static final Pattern TYPOGRAPHY_PATTERN_13 = compile(\"\\u00a0 \");\n  private static final Pattern TYPOGRAPHY_PATTERN_14 = compile(\" \\u00a0\");\n  private static final Pattern TYPOGRAPHY_PATTERN_15 = compile(\" \\u202f\");\n  private static final Pattern TYPOGRAPHY_PATTERN_16 = compile(\"\\u202f \");\n\n  private static final String FRENCH_SHORT_CODE = \"fr\";\n\n  private static volatile Throwable instantiationTrace;\n\n  /**\n   * @deprecated don't use this method besides the inheritance or core code. Languages are not supposed to be\n   * instantiated multiple times. They may contain heavy data which may waste the memory.\n   * Use {@link #getInstance()} instead.\n   */\n  @Deprecated\n  public French() {\n    Throwable trace = instantiationTrace;\n    if (trace != null) {\n      throw new RuntimeException(\"Language was already instantiated, see the cause stacktrace below.\", trace);\n    }\n    instantiationTrace = new Throwable();\n  }\n\n  /**\n   * This is a fake constructor overload for the subclasses. Public constructors can only be used by the LT itself.\n   */\n  protected French(boolean fakeValue) {\n  }\n\n  @Override\n  public SentenceTokenizer createDefaultSentenceTokenizer() {\n    return new SRXSentenceTokenizer(this);\n  }\n\n  @Override\n  public String getName() {\n    return \"French\";","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-language-modules/fr/src/main/java/org/languagetool/language/French.java#L66-L102","documentation":"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.","triggerScenarios":"Calling new French() (the deprecated constructor) more than once — or after the singleton was created via getInstance()/Languages registry.","commonSituations":"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.","solutions":["Replace new French() with French.getInstance() or Languages.getLanguageForShortCode(\"fr\").","Migrate off the deprecated constructor entirely — it is designed to fail on duplicate use.","Check the embedded cause trace to find the earlier instantiation and remove it."],"exampleFix":"// before\nFrench french = new French();\n// after\nFrench french = French.getInstance();","handlingStrategy":"validation","validationCode":"// Obtain the singleton instead of the deprecated constructor:\nFrench french = French.getInstance(); // or Languages.getLanguageForShortCode(\"fr\")","typeGuard":null,"tryCatchPattern":"try {\n  new French();\n} catch (RuntimeException e) {\n  e.getCause().printStackTrace(); // first instantiation site\n}","preventionTips":["Migrate legacy code off the deprecated new French() constructor","Use French.getInstance() everywhere","Treat compiler deprecation warnings on the constructor as errors"],"tags":["java","languagetool","singleton","deprecated-api"],"backgroundTag":"deprecated-api-usage","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}