Skip to content

Commit e8af58a

Browse files
Fix handling of missing columns in rows
1 parent 37aa780 commit e8af58a

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

client-java/controller/src/main/java/org/evomaster/client/java/controller/cassandra/calculator/CassandraOperationEvaluator.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ private Truthness evaluateLessThanEquals(LessThanEqualsOperation<?> op, Cassandr
113113

114114
private Truthness evaluateIn(InOperation op, CassandraRow candidateRow) {
115115
Object rowValue = candidateRow.getValue(op.getColumnName());
116+
if (rowValue == null) {
117+
return FALSE_TRUTHNESS;
118+
}
116119

117120
return any(rowValue, op.getValues());
118121
}
@@ -121,17 +124,17 @@ private Truthness evaluateContains(ContainsOperation<?> op, CassandraRow candida
121124
Object rawCol = candidateRow.getValue(op.getColumnName());
122125
if (rawCol == null) {
123126
return FALSE_TRUTHNESS;
124-
} else {
125-
return any(op.getValue(), toElementList(rawCol));
126127
}
128+
129+
return any(op.getValue(), toElementList(rawCol));
127130
}
128131

129132
private Truthness evaluateContainsKey(ContainsKeyOperation<?> op, CassandraRow candidateRow) {
130133
Object rawCol = candidateRow.getValue(op.getColumnName());
131134
if (rawCol == null) {
132135
return FALSE_TRUTHNESS;
133136
} else if (!(rawCol instanceof Map<?, ?>)) {
134-
return FALSE_TRUTHNESS;
137+
throw new IllegalArgumentException("CONTAINS KEY is only supported on map columns, got: " + rawCol.getClass().getName());
135138
} else {
136139
List<?> keys = new ArrayList<>(((Map<?, ?>) rawCol).keySet());
137140
return any(op.getValue(), keys);
@@ -142,10 +145,8 @@ private Truthness evaluateComparison(ComparisonOperation<?> op, CassandraRow can
142145
Object rowValue = candidateRow.getValue(op.getColumnName());
143146
Object queryValue = op.getValue();
144147

145-
if (rowValue == null && queryValue == null) {
148+
if (rowValue == null) {
146149
return FALSE_TRUTHNESS;
147-
} else if (rowValue == null || queryValue == null) {
148-
return FALSE_TRUTHNESS_BETTER;
149150
} else {
150151
Truthness typeResult = compareByType(rowValue, queryValue, type);
151152
if (typeResult.isTrue()) {
@@ -385,18 +386,12 @@ private Truthness any(Object value, List<?> candidates) {
385386
}
386387

387388
private Truthness evaluateEquals(Object a, Object b) {
388-
if (a == null && b == null) {
389-
return FALSE_TRUTHNESS;
390-
} else if (a == null || b == null) {
391-
return FALSE_TRUTHNESS_BETTER;
392-
} else {
393-
Truthness raw = compareByType(a, b, ComparisonType.EQUALS);
394-
if (raw.isTrue()) {
395-
return raw;
396-
} else {
397-
return TruthnessUtils.buildScaledTruthness(C_BETTER, raw.getOfTrue());
398-
}
389+
Truthness unscaledTruthness = compareByType(a, b, ComparisonType.EQUALS);
390+
if (unscaledTruthness.isTrue()) {
391+
return unscaledTruthness;
399392
}
393+
394+
return TruthnessUtils.buildScaledTruthness(C_BETTER, unscaledTruthness.getOfTrue());
400395
}
401396

402397
private static List<?> toElementList(Object collection) {

0 commit comments

Comments
 (0)