SonarSource/sonarqube · error · java.lang.IllegalStateException
No column has been defined
Error message
No column has been defined
What it means
Thrown by AddColumnsBuilder.build() when ALTER TABLE SQL generation is requested but no column was registered. The builder produces 'ALTER TABLE ... ADD COLUMN ...' statements and requires at least one columnDef added via addColumn().
Solutions
- Add at least one addColumn(...) call before build().
- If the column may already exist, skip creating/invoking the builder entirely instead of building it empty.
- Guard build() with a check on the batch's column count.
Example fix
// before
AddColumnsBuilder add = new AddColumnsBuilder(dialect, "issues");
String sql = add.build();
// after
AddColumnsBuilder add = new AddColumnsBuilder(dialect, "issues");
add.addColumn(newVarcharColumnDefBuilder().setColumnName("branch").setLimit(255).build());
String sql = add.build(); Defensive patterns
Strategy: validation
Validate before calling
if (builderColumns.isEmpty()) { throw new IllegalArgumentException("AddColumnsBuilder requires at least one column"); } Prevention
- Always call addColumn(...) immediately after constructing the builder
- Wrap builder construction and build() together so emptiness is obvious
- Skip the migration step entirely when there is nothing to add
- Code-review custom migrations for unconditional build() calls
When it happens
Trigger: Calling build() on an AddColumnsBuilder without ever calling addColumn(...), e.g. a migration that conditionally skips adding columns but still builds the statement.
Common situations: Custom migration code guarded by a schema check where all branches fail to add columns; copy-pasted migration that forgot the addColumn call; refactored migration where columnDefs list ended up empty.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- No column has been defined
- Column with autoincrement is neither BigInteger, Integer…
- Error during processing of row
- Fail to execute
- Fail to execute %n (caught error, original was )
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/9f5f88f6cf8355f3.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/AddColumnsBuilder.java:53
public class AddColumnsBuilder {
private final Dialect dialect;
private final String tableName;
private List<ColumnDef> columnDefs = newArrayList();
public AddColumnsBuilder(Dialect dialect, String tableName) {
this.tableName = validateTableName(tableName);
this.dialect = dialect;
}
public AddColumnsBuilder addColumn(ColumnDef columnDef) {
columnDefs.add(columnDef);
return this;
}
public String build() {
if (columnDefs.isEmpty()) {
throw new IllegalStateException("No column has been defined");
}
StringBuilder sql = new StringBuilder().append("ALTER TABLE ").append(tableName).append(" ");
switch (dialect.getId()) {
case PostgreSql.ID:
addColumns(sql, "ADD COLUMN ");
break;
case MsSql.ID:
sql.append("ADD ");
addColumns(sql, "");
break;
default:
sql.append("ADD (");
addColumns(sql, "");
sql.append(")");
}
return sql.toString();
}View on GitHub (pinned to 184c821202)