languagetool-org/languagetool · error · RuntimeException

Error storing matches for '${sentence.getTitle()}'

Error message

Error storing matches for '${sentence.getTitle()}'

What it means

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.

Source

Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/dumpcheck/DatabaseHandler.java:139

        insertSt.setString(11, sentence.getUrl());
        insertSt.setString(12, sentence.getSource());
        insertSt.addBatch();
        if (++batchCount >= batchSize){
          executeBatch();
          batchCount = 0;
        }

        checkMaxErrors(++errorCount);
        if (errorCount % 100 == 0) {
          System.out.println("Storing error #" + errorCount + " for text:");
          System.out.println("  " + sentence.getText());
        }
      }
      checkMaxSentences(++sentenceCount);
    } catch (DocumentLimitReachedException | ErrorLimitReachedException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException("Error storing matches for '" + sentence.getTitle() + "'", e);
    }
  }

  private void executeBatch() throws SQLException {
    boolean autoCommit = conn.getAutoCommit();
    conn.setAutoCommit(false);
    try {
      insertSt.executeBatch();
      if (autoCommit) {
        conn.commit();
      }
    } finally {
      conn.setAutoCommit(autoCommit);
    }
  }

  @Override
  public void close() throws Exception {

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Inspect the cause chain (getCause) for the underlying SQLException
  2. Verify DB connectivity and increase wait_timeout / reconnect settings for long runs
  3. Check schema constraints and column sizes against the sentence/match data
  4. Re-run from the failing document; enable smaller batch commits

Example fix

// before
throw new RuntimeException("Error storing matches for '" + sentence.getTitle() + "'", e);
// after
LOG.error("Error storing matches for '" + sentence.getTitle() + "'", e);
conn.rollback();
throw new RuntimeException("Error storing matches for '" + sentence.getTitle() + "'", e);
Defensive patterns

Strategy: try-catch

Validate before calling

try (Connection c = DriverManager.getConnection(dbUrl, dbUser, dbPassword)) {
  if (!c.isValid(5)) throw new IllegalStateException("DB connection invalid before run");
}

Try / catch

try {
  handler.handleResult(sentence, matches, language);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Error storing matches")) {
    log.error("DB write failed for " + sentence.getTitle() + ": " + e.getCause(), e);
    // skip sentence or retry with fresh connection
  } else throw e;
}

Prevention

When it happens

Trigger: executeBatch or the prepared-statement inserts throw a SQLException; the DB connection dropped; a sentence exceeds a column length; a commit fails during batching.

Common situations: 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.

Related errors


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