pentaho/pentaho-kettle · error · IllegalArgumentException
Key already added [key= ]
Error message
Key already added [key={key}] What it means
KeyValueSet.add() enforces unique keys within the set. If a KeyValue with an already-present key is added, it throws IllegalArgumentException('Key already added [key=...]'). KeyValueSet is a keyed collection, so duplicate keys would silently overwrite otherwise.
Solutions
- Deduplicate the KeyValue array before calling add (e.g. via a LinkedHashMap keyed by getKey()).
- Decide on overwrite semantics: remove the existing entry first or use put()/update if the API supports replacing.
- Log or surface the duplicate source item instead of adding it blindly.
Example fix
// before
set.add(new KeyValue<>("retries", 3));
set.add(new KeyValue<>("retries", 5)); // throws
// after
Map<String, KeyValue<?>> unique = new LinkedHashMap<>();
for (KeyValue<?> kv : keyValues) unique.putIfAbsent(kv.getKey(), kv);
set.add(unique.values().toArray(new KeyValue<?>[0])); Defensive patterns
Strategy: validation
Validate before calling
Set<String> seen = new HashSet<>();
for (KeyValue<?> kv : keyValues) {
if (!seen.add(kv.getKey())) {
throw new IllegalArgumentException("Duplicate key in input: " + kv.getKey());
}
} Try / catch
try {
set.add(keyValues);
} catch (IllegalArgumentException e) {
// extract duplicate key from message and report source item, or deduplicate and retry
} Prevention
- Deduplicate parsed parameter lists before building the KeyValueSet.
- Decide explicitly between add (fail on duplicate) and replace semantics per use case.
- Log duplicate sources (file line, request param) so users can fix the input.
When it happens
Trigger: Calling add(keyValue...) (or the fluent chain) with two KeyValue instances sharing the same key, including re-adding a key that was added in a previous add() call on the same set.
Common situations: Building a set from a list of parsed parameters where duplicates exist (repeated query/CLI parameters); loop code re-adding the same KeyValue; copy-paste of field definitions.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Destination must be a folder / invalid drag-drop source…
- is already included.
- Key contains invalid characters
- Key must not be '_'
- Key must not end with '-'
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/626510b44848f489.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/core/util/KeyValueSet.java:54
/**
* Serial version UID.
*/
private static final long serialVersionUID = 925133158112717153L;
private final Map<String, KeyValue<?>> entries = new TreeMap<String, KeyValue<?>>();
/**
* Add key value(s).
*
* @param keyValues
* key values to add.
* @return this.
*/
public KeyValueSet add( final KeyValue<?>... keyValues ) {
for ( KeyValue<?> keyValue : keyValues ) {
if ( this.entries.containsKey( keyValue.getKey() ) ) {
throw new IllegalArgumentException( "Key already added [key=" + keyValue.getKey() + "]" );
}
this.entries.put( keyValue.getKey(), keyValue );
}
return this;
}
/**
* {@inheritDoc}
*
* @see java.lang.Iterable#iterator()
*/
public Iterator<KeyValue<?>> iterator() {
return this.keyValues().iterator();
}
/**
* @param key
* the key.View on GitHub (pinned to f3058517a1)