Skip to content

Commit 310baab

Browse files
author
chengyitian
committed
AJ-461: check if newColName is null or empty; check if newColName already exit in table.
1 parent 354597a commit 310baab

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/com/xxdb/data/BasicTable.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,17 @@ public void setColName (final List<String> colNames) {
129129
* @param newColName
130130
*/
131131
public void replaceColName(String originalColName, String newColName) {
132-
if (Utils.isEmpty(originalColName))
133-
throw new RuntimeException("colName cannot be null.");
132+
if (Objects.isNull(newColName) || Utils.isEmpty(newColName))
133+
throw new RuntimeException("The param 'newColName' cannot be null or empty.");
134+
135+
if (this.colNames.contains(newColName))
136+
throw new RuntimeException("The newColName '" + newColName +"' already exists in table. Column names cannot be duplicated.");
134137

135138
if (this.colNames.contains(originalColName)) {
136139
int index = colNames.indexOf(originalColName);
137140
colNames.set(index, newColName);
138141
} else {
139-
throw new RuntimeException("colName '" + originalColName +"' does not exist in table.");
142+
throw new RuntimeException("The param originalColName '" + originalColName +"' does not exist in table.");
140143
}
141144
}
142145

0 commit comments

Comments
 (0)