{"record":{"id":"19d9628d4b2c4072","repo":"languagetool-org/languagetool","slug":"error-storing-matches-for-sentence-gettitle","errorCode":null,"errorMessage":"Error storing matches for '${sentence.getTitle()}'","messagePattern":"Error storing matches for '(.+?)'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-wikipedia/src/main/java/org/languagetool/dev/dumpcheck/DatabaseHandler.java","lineNumber":139,"sourceCode":"        insertSt.setString(11, sentence.getUrl());\n        insertSt.setString(12, sentence.getSource());\n        insertSt.addBatch();\n        if (++batchCount >= batchSize){\n          executeBatch();\n          batchCount = 0;\n        }\n\n        checkMaxErrors(++errorCount);\n        if (errorCount % 100 == 0) {\n          System.out.println(\"Storing error #\" + errorCount + \" for text:\");\n          System.out.println(\"  \" + sentence.getText());\n        }\n      }\n      checkMaxSentences(++sentenceCount);\n    } catch (DocumentLimitReachedException | ErrorLimitReachedException e) {\n      throw e;\n    } catch (Exception e) {\n      throw new RuntimeException(\"Error storing matches for '\" + sentence.getTitle() + \"'\", e);\n    }\n  }\n\n  private void executeBatch() throws SQLException {\n    boolean autoCommit = conn.getAutoCommit();\n    conn.setAutoCommit(false);\n    try {\n      insertSt.executeBatch();\n      if (autoCommit) {\n        conn.commit();\n      }\n    } finally {\n      conn.setAutoCommit(autoCommit);\n    }\n  }\n\n  @Override\n  public void close() throws Exception {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-wikipedia/src/main/java/org/languagetool/dev/dumpcheck/DatabaseHandler.java#L121-L157","documentation":"DatabaseHandler.handleResult wraps any unexpected exception occurring while persisting rule matches for a sentence into a RuntimeException identifying the sentence title. Only DocumentLimitReachedException and ErrorLimitReachedException are re-thrown untouched; everything else (SQL errors, constraint violations) is wrapped. It signals the write path to the database failed mid-processing.","triggerScenarios":"executeBatch or the prepared-statement inserts throw a SQLException; the DB connection dropped; a sentence exceeds a column length; a commit fails during batching.","commonSituations":"MySQL server gone away on long dumps; duplicate-key/constraint errors in the matches table; column too small for long sentence text; connection pool timeout on large Wikipedia dumps.","solutions":["Inspect the cause chain (getCause) for the underlying SQLException","Verify DB connectivity and increase wait_timeout / reconnect settings for long runs","Check schema constraints and column sizes against the sentence/match data","Re-run from the failing document; enable smaller batch commits"],"exampleFix":"// before\nthrow new RuntimeException(\"Error storing matches for '\" + sentence.getTitle() + \"'\", e);\n// after\nLOG.error(\"Error storing matches for '\" + sentence.getTitle() + \"'\", e);\nconn.rollback();\nthrow new RuntimeException(\"Error storing matches for '\" + sentence.getTitle() + \"'\", e);","handlingStrategy":"try-catch","validationCode":"try (Connection c = DriverManager.getConnection(dbUrl, dbUser, dbPassword)) {\n  if (!c.isValid(5)) throw new IllegalStateException(\"DB connection invalid before run\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  handler.handleResult(sentence, matches, language);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Error storing matches\")) {\n    log.error(\"DB write failed for \" + sentence.getTitle() + \": \" + e.getCause(), e);\n    // skip sentence or retry with fresh connection\n  } else throw e;\n}","preventionTips":["Increase MySQL wait_timeout and enable autoReconnect for long dumps","Size text columns (TEXT/MEDIUMTEXT) for long sentences","Commit in smaller batches","Monitor connection health during bulk runs"],"tags":["database","sql","persistence"],"backgroundTag":"database-write-failed","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}