{"record":{"id":"3318859447f472f3","repo":"SonarSource/sonarqube","slug":"unsupported-db","errorCode":null,"errorMessage":"Unsupported DB: ","messagePattern":"Unsupported DB: ","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropTableBuilder.java","lineNumber":48,"sourceCode":"import static java.util.Collections.singletonList;\nimport static java.util.Objects.requireNonNull;\nimport static org.sonar.server.platform.db.migration.def.Validations.validateTableName;\n\npublic class DropTableBuilder {\n\n  private final Dialect dialect;\n  private final String tableName;\n\n  public DropTableBuilder(Dialect dialect, String tableName) {\n    this.dialect = requireNonNull(dialect, \"dialect can't be null\");\n    this.tableName = validateTableName(tableName);\n  }\n\n  public List<String> build() {\n    return switch (dialect.getId()) {\n      case Oracle.ID -> forOracle(tableName);\n      case H2.ID, PostgreSql.ID, MsSql.ID -> singletonList(\"drop table if exists \" + tableName);\n      default -> throw new IllegalStateException(\"Unsupported DB: \" + dialect.getId());\n    };\n  }\n\n  private static List<String> forOracle(String tableName) {\n    return asList(\n      dropIfExistsOnOracle(\"DROP SEQUENCE \" + tableName + \"_seq\", -2289),\n      dropIfExistsOnOracle(\"DROP TRIGGER \" + tableName + \"_idt\", -4080),\n      dropIfExistsOnOracle(\"DROP TABLE \" + tableName, -942));\n  }\n\n  private static String dropIfExistsOnOracle(String command, int codeIfNotExists) {\n    return \"BEGIN\\n\" +\n      \"EXECUTE IMMEDIATE '\" + command + \"';\\n\" +\n      \"EXCEPTION\\n\" +\n      \"WHEN OTHERS THEN\\n\" +\n      \"  IF SQLCODE != \" + codeIfNotExists + \" THEN\\n\" +\n      \"  RAISE;\\n\" +\n      \"  END IF;\\n\" +","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropTableBuilder.java#L30-L66","documentation":"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.","triggerScenarios":"Calling DropTableBuilder.build() in a migration when the Dialect id is not oracle, h2, postgresql, or mssql.","commonSituations":"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.","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."],"exampleFix":"// before\ndefault -> throw new IllegalStateException(\"Unsupported DB: \" + dialect.getId());\n// after\ncase MySql.ID -> singletonList(\"DROP TABLE IF EXISTS \" + tableName);\ndefault -> throw new IllegalStateException(\"Unsupported DB: \" + dialect.getId());","handlingStrategy":"validation","validationCode":"if (!List.of(Oracle.ID, H2.ID, PostgreSql.ID, MsSql.ID).contains(dialect.getId())) {\n  throw new IllegalArgumentException(\"DropTableBuilder unsupported dialect \" + dialect.getId());\n}","typeGuard":"boolean supportsDropTable(Dialect d) { return Set.of(Oracle.ID, H2.ID, PostgreSql.ID, MsSql.ID).contains(d.getId()); }","tryCatchPattern":"try {\n  dropStatements = new DropTableBuilder(dialect, tableName).build();\n} catch (IllegalStateException e) {\n  LOG.error(\"Skip table drop: {}\", e.getMessage());\n}","preventionTips":["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."],"tags":["database","migration","unsupported-dialect","ddl"],"backgroundTag":"unsupported-enum-value","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}