SonarSource/sonarqube · error · java.lang.IllegalStateException
Unsupported DB:
Error message
Unsupported DB:
What it means
DropTableBuilder.build() emits a "drop table if exists" statement for H2/PostgreSql/MsSql and a special Oracle variant (with sequence/trigger cleanup). Any other dialect id throws IllegalStateException "Unsupported DB: <id>". Oracle differs because it lacks IF EXISTS and needs companion objects dropped.
Source
Thrown at server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropTableBuilder.java:48
import static java.util.Collections.singletonList;
import static java.util.Objects.requireNonNull;
import static org.sonar.server.platform.db.migration.def.Validations.validateTableName;
public class DropTableBuilder {
private final Dialect dialect;
private final String tableName;
public DropTableBuilder(Dialect dialect, String tableName) {
this.dialect = requireNonNull(dialect, "dialect can't be null");
this.tableName = validateTableName(tableName);
}
public List<String> build() {
return switch (dialect.getId()) {
case Oracle.ID -> forOracle(tableName);
case H2.ID, PostgreSql.ID, MsSql.ID -> singletonList("drop table if exists " + tableName);
default -> throw new IllegalStateException("Unsupported DB: " + dialect.getId());
};
}
private static List<String> forOracle(String tableName) {
return asList(
dropIfExistsOnOracle("DROP SEQUENCE " + tableName + "_seq", -2289),
dropIfExistsOnOracle("DROP TRIGGER " + tableName + "_idt", -4080),
dropIfExistsOnOracle("DROP TABLE " + tableName, -942));
}
private static String dropIfExistsOnOracle(String command, int codeIfNotExists) {
return "BEGIN\n" +
"EXECUTE IMMEDIATE '" + command + "';\n" +
"EXCEPTION\n" +
"WHEN OTHERS THEN\n" +
" IF SQLCODE != " + codeIfNotExists + " THEN\n" +
" RAISE;\n" +
" END IF;\n" +View on GitHub (pinned to 184c821202)
Solutions
- Run SonarQube only on a supported database platform for your version.
- Check sonar.jdbc.dialect configuration for typos or custom values.
- When adding a dialect, update DropTableBuilder's switch alongside the new Dialect class.
Example fix
// before
default -> throw new IllegalStateException("Unsupported DB: " + dialect.getId());
// after
case MySql.ID -> singletonList("DROP TABLE IF EXISTS " + tableName);
default -> throw new IllegalStateException("Unsupported DB: " + dialect.getId()); Defensive patterns
Strategy: validation
Validate before calling
if (!List.of(Oracle.ID, H2.ID, PostgreSql.ID, MsSql.ID).contains(dialect.getId())) {
throw new IllegalArgumentException("DropTableBuilder unsupported dialect " + dialect.getId());
} Type guard
boolean supportsDropTable(Dialect d) { return Set.of(Oracle.ID, H2.ID, PostgreSql.ID, MsSql.ID).contains(d.getId()); } Try / catch
try {
dropStatements = new DropTableBuilder(dialect, tableName).build();
} catch (IllegalStateException e) {
LOG.error("Skip table drop: {}", e.getMessage());
} Prevention
- Keep a registry test asserting every builder handles every supported dialect id.
- Avoid custom dialect hacks in test harnesses; use real Dialect instances.
- Drop only tables that were created by the same migration framework.
When it happens
Trigger: Calling DropTableBuilder.build() in a migration when the Dialect id is not oracle, h2, postgresql, or mssql.
Common situations: Pointing SonarQube at an unsupported database; adding a new Dialect implementation without updating every SQL builder in sonar-db-migration; unit tests injecting a stub dialect.
Related errors
- Unsupported database dialect:
- Unsupported dialect for drop of constraint:
- Unsupported database '%s'
- Unsupported dialect id
- Unsupported dialect id
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/3318859447f472f3.
Report an issue: GitHub.