SonarSource/sonarqube · error · java.lang.IllegalStateException
Column with autoincrement is neither BigInteger, Integer…
Error message
Column with autoincrement is neither BigInteger, Integer, nor SmallInt
What it means
Thrown by CreateTableBuilder.appendDataType when a column is marked auto-increment but its type is not BigInteger, Integer, or SmallInt. Only those numeric types map to AUTO_INCREMENT/BIGSERIAL/SERIAL/SMALLSERIAL dialect SQL.
Solutions
- Change the column type to BigIntegerColumnDef, IntegerColumnDef, or SmallIntColumnDef.
- Remove the auto-increment flag if the column should not be a generated key.
- Verify columnDef type matches the intended primary-key semantics.
Example fix
// before
newVarcharColumnDefBuilder().setColumnName("id").setIsNullable(false).setLimit(40).build() // with autoincrement
// after
newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).setAutoIncrement(true).build() Defensive patterns
Strategy: validation
Validate before calling
if (columnDef.isAutoIncrement() && !(columnDef instanceof BigIntegerColumnDef || columnDef instanceof IntegerColumnDef || columnDef instanceof SmallIntColumnDef)) { throw new IllegalArgumentException("autoincrement requires integer type"); } Type guard
boolean isAutoIncrementCapable(ColumnDef c) { return c instanceof BigIntegerColumnDef || c instanceof IntegerColumnDef || c instanceof SmallIntColumnDef; } Prevention
- Only set auto-increment on integer-family columns
- Keep PK column type and auto-increment flags consistent
- Review generated/copy-pasted column builders for type/flag mismatches
When it happens
Trigger: Building a CREATE TABLE where a column def was created with setIsNullable(false) plus auto-increment on a Varchar/Decimal/Text column.
Common situations: Custom migration accidentally enabling auto-increment on a non-integer key column; copy-pasted column builder with wrong type; generated migration code with mismatched column type.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Error during processing of row
- Fail to execute
- Fail to execute %n (caught error, original was )
- Failed to create table schema_migrations
- Failed to insert row with value
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/1b73795ca19d5f6d.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilder.java:160
appendDefaultValue(res, columnDef);
appendNullConstraint(res, columnDef);
appendColumnFlags(res, dialect, columnDef);
if (columnDefIterator.hasNext()) {
res.append(',');
}
}
}
private void appendDataType(StringBuilder res, Dialect dialect, ColumnDef columnDef) {
if (PostgreSql.ID.equals(dialect.getId()) && isAutoIncrement(columnDef)) {
if (columnDef instanceof BigIntegerColumnDef) {
res.append("BIGSERIAL");
} else if (columnDef instanceof IntegerColumnDef) {
res.append("SERIAL");
} else if (columnDef instanceof SmallIntColumnDef) {
res.append("SMALLSERIAL");
} else {
throw new IllegalStateException("Column with autoincrement is neither BigInteger, Integer, nor SmallInt");
}
} else {
res.append(columnDef.generateSqlType(dialect));
}
}
private boolean isAutoIncrement(ColumnDef columnDef) {
Collection<ColumnFlag> columnFlags = this.flagsByColumn.get(columnDef);
return columnFlags.contains(ColumnFlag.AUTO_INCREMENT);
}
private static void appendNullConstraint(StringBuilder res, ColumnDef columnDef) {
if (columnDef.isNullable()) {
res.append(" NULL");
} else {
res.append(" NOT NULL");
}
}View on GitHub (pinned to 184c821202)