pentaho/pentaho-kettle · error · IllegalArgumentException

Key must not end with '-'

Error message

Key must not end with '-'

What it means

KeyValue.assertKey() rejects keys that end with '-' because a trailing hyphen is ambiguous or awkward in downstream usages (env vars, flags, concatenation). It throws IllegalArgumentException('Key must not end with \'-\'').

Solutions

  1. Strip trailing '-' characters before creating the KeyValue.
  2. Fix key-building logic to avoid appending a separator when the suffix is empty.
  3. Normalize keys with a helper that trims leading/trailing hyphens and validates with assertKey.

Example fix

// before
String key = "retries-"; // built as "retries" + "-" + emptySuffix
new KeyValue<>(key, 5);
// after
String key = ("retries" + "-" + suffix).replaceAll("^-+|-+$", "");
new KeyValue<>(key, 5); // "retries"
Defensive patterns

Strategy: validation

Validate before calling

if (key.endsWith("-")) {
  throw new IllegalArgumentException("Key must not end with '-': " + key);
}

Try / catch

try {
  new KeyValue<>(key, value);
} catch (IllegalArgumentException e) {
  key = key.replaceAll("-+$", "");
}

Prevention

When it happens

Trigger: Constructing a KeyValue with a key such as 'retries-' — often the result of appending separators during programmatic key building (prefix + '-' with an empty suffix).

Common situations: Dynamic key construction where a suffix is optional: "prefix-" + suffix with empty suffix; templated keys with placeholder removed leaving a trailing dash.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/a26a58c9c8f352c6. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/core/util/KeyValue.java:96

  }

  /**
   * @param lowerKey
   *          key to test.
   * @throws IllegalArgumentException
   *           if key is invalid.
   */
  public static final void assertKey( final String lowerKey ) throws IllegalArgumentException {
    Assert.assertNotEmpty( lowerKey, "Key cannot be null or empty" );
    if ( !StringUtils.containsOnly( lowerKey, VALID_KEY_CHARS ) ) {
      throw new IllegalArgumentException( "Key contains invalid characters [validKeyCharacters="
        + VALID_KEY_CHARS + "]" );
    }
    if ( lowerKey.charAt( 0 ) == '-' ) {
      throw new IllegalArgumentException( "Key must not start with '-'" );
    }
    if ( lowerKey.endsWith( "-" ) ) {
      throw new IllegalArgumentException( "Key must not end with '-'" );
    }
    if ( "_".equals( lowerKey ) ) {
      throw new IllegalArgumentException( "Key must not be  '_'" );
    }
  }

  /**
   * @return the key, never null.
   */
  public String getKey() {
    return this.key;
  }

  /**
   * @return the value
   */
  public T getValue() {
    return this.value;

View on GitHub (pinned to f3058517a1)