{"record":{"id":"2642439a7ec5daec","repo":"SonarSource/sonarqube","slug":"unsupported-dialect-for-drop-of-constraint","errorCode":null,"errorMessage":"Unsupported dialect for drop of constraint: ","messagePattern":"Unsupported dialect for drop of constraint: ","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/DropConstraintBuilder.java","lineNumber":70,"sourceCode":"\n  public DropConstraintBuilder setName(String s) {\n    if (s.startsWith(\"pk_\")) {\n      throw new IllegalArgumentException(\"This builder should not be used with primary keys\");\n    }\n    this.constraintName = s;\n    return this;\n  }\n\n  public List<String> build() {\n    validateTableName(tableName);\n    validateIndexName(constraintName);\n    return singletonList(createSqlStatement());\n  }\n\n  private String createSqlStatement() {\n    return switch (dialect.getId()) {\n      case MsSql.ID, Oracle.ID, PostgreSql.ID, H2.ID -> \"ALTER TABLE \" + tableName + \" DROP CONSTRAINT \" + constraintName;\n      default -> throw new IllegalStateException(\"Unsupported dialect for drop of constraint: \" + dialect);\n    };\n  }\n}\n","sourceCodeStart":52,"sourceCodeEnd":74,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java#L52-L74","documentation":"DropConstraintBuilder.build() generates the ALTER TABLE ... DROP CONSTRAINT statement only for the four supported dialects (MsSql, Oracle, PostgreSql, H2). If the configured Dialect's id is none of these, createSqlStatement throws an IllegalStateException naming the dialect. This is a defensive guard: Sonar's migration SQL builders only support the dialects they ship drivers/support for.","triggerScenarios":"Calling DropConstraintBuilder.build() (via MassUpdate/DbVersion steps) with a Dialect whose getId() returns anything other than \"mssql\", \"oracle\", \"postgresql\", or \"h2\" — e.g. a custom or newer dialect id.","commonSituations":"Running a custom SonarQube build against an experimental/new database dialect; a plugin or test stub supplying a mock Dialect with an unknown id; a dialect registry updated without updating all SQL builders.","solutions":["Check sonar.jdbc.dialect / sonar.properties — run migrations only on a supported database (MS SQL, Oracle, PostgreSQL, H2).","If a new dialect was added, update DropConstraintBuilder.createSqlStatement's switch to include its ID.","Fix test harnesses that construct a fake Dialect with an unrecognized id."],"exampleFix":"// before\ndefault -> throw new IllegalStateException(\"Unsupported dialect for drop of constraint: \" + dialect);\n// after\ncase MySql.ID -> \"ALTER TABLE \" + tableName + \" DROP FOREIGN KEY \" + constraintName;\ndefault -> throw new IllegalStateException(\"Unsupported dialect for drop of constraint: \" + dialect);","handlingStrategy":"validation","validationCode":"// Java\nimport static org.sonar.db.dialect.DialectId.*;\nboolean supported = List.of(MsSql.ID, Oracle.ID, PostgreSql.ID, H2.ID).contains(dialect.getId());\nif (!supported) throw new IllegalArgumentException(\"Drop constraint not supported for dialect \" + dialect.getId());","typeGuard":"boolean supportsDropConstraint(Dialect d) { return Set.of(MsSql.ID, Oracle.ID, PostgreSql.ID, H2.ID).contains(d.getId()); }","tryCatchPattern":"try {\n  statements = new DropConstraintBuilder(dialect, table, constraint).build();\n} catch (IllegalStateException e) {\n  LOG.error(\"Dialect {} cannot drop constraints: {}\", dialect.getId(), e.getMessage());\n}","preventionTips":["Only run sonar-db-migration steps against the four supported dialects.","When adding a Dialect id, add its case to every SQL builder switch in one change.","Add a unit test per builder iterating all registered dialect ids."],"tags":["database","migration","unsupported-dialect","sql-generation"],"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"}