SonarSource/sonarqube · error · java.lang.IllegalStateException

Unsupported database '%s'

Error message

Unsupported database '%s'

What it means

DropPrimaryKeySqlGenerator.generate() switches on the dialect id (postgresql, mssql, oracle, h2) to emit dialect-specific DROP PRIMARY KEY statements. Any other dialect id hits the default branch and throws an IllegalStateException formatted as "Unsupported database '%s'". The generator supports only the dialects listed in its switch.

Source

Thrown at server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropPrimaryKeySqlGenerator.java:70

  }

  public List<String> generate(String tableName, Collection<String> columnNames, boolean isAutoGenerated) throws SQLException {
    Dialect dialect = db.getDialect();
    Optional<String> constraintName = dbConstraintFinder.findConstraintName(tableName);
    if (!constraintName.isPresent()) {
      return Collections.emptyList();
    }
    switch (dialect.getId()) {
      case PostgreSql.ID:
        return generateForPostgresSql(tableName, columnNames, constraintName.get());
      case MsSql.ID:
        return generateForMsSql(tableName, constraintName.get());
      case Oracle.ID:
        return generateForOracle(tableName, constraintName.get(), isAutoGenerated);
      case H2.ID:
        return generateForH2(tableName, constraintName.get());
      default:
        throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
    }
  }

  private List<String> generateForPostgresSql(String tableName, Collection<String> columns, String constraintName) throws SQLException {
    List<String> statements = new ArrayList<>();
    for (String column : columns) {
      statements.add(format("ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT", tableName, column));
      String sequence = dbConstraintFinder.getPostgresSqlSequence(tableName, column);
      if (sequence != null) {
        statements.add(format("DROP SEQUENCE %s", sequence));
      }
    }

    statements.add(format(GENERIC_DROP_CONSTRAINT_STATEMENT, tableName, constraintName));
    return statements;
  }

  private static List<String> generateForOracle(String tableName, String constraintName, boolean isAutoGenerated) {

View on GitHub (pinned to 184c821202)

Solutions

  1. Verify sonar.jdbc.dialect matches a supported value and that the database is officially supported for this SonarQube version.
  2. If supporting a new engine, implement the dialect's Dialect class AND add a case in DropPrimaryKeySqlGenerator (e.g. generateForXxx).
  3. Test migrations on H2 only for dev, never expect H2-specific paths to cover other engines.

Example fix

// before
default:
  throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
// after
case MySql.ID:
  return List.of(format("ALTER TABLE %s DROP PRIMARY KEY", tableName));
default:
  throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
Defensive patterns

Strategy: validation

Validate before calling

if (!Set.of("postgresql", "mssql", "oracle", "h2").contains(dialect.getId())) {
  throw new IllegalArgumentException("DropPrimaryKeySqlGenerator does not support " + dialect.getId());
}

Type guard

boolean supportedForDropPk(Dialect d) { return Set.of(PostgreSql.ID, MsSql.ID, Oracle.ID, H2.ID).contains(d.getId()); }

Try / catch

try {
  sqls = new DropPrimaryKeySqlGenerator(dialect).generate(tableName, columns, isAutoGenerated);
} catch (IllegalStateException e) {
  LOG.error("Cannot drop primary key on {}: {}", tableName, e.getMessage());
}

Prevention

When it happens

Trigger: Invoking generate() during a migration step that drops a primary key while the configured Dialect id is not one of postgresql/mssql/oracle/h2 (e.g. an unknown or newly added dialect id).

Common situations: Installing SonarQube on an unsupported or brand-new database engine; a misconfigured sonar.jdbc.dialect value; running on a database fork whose driver reports a different dialect id.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/99af76aadc791dba. Report an issue: GitHub.