apache/flink · error · IllegalArgumentException

Cannot find empty string.

Error message

Cannot find empty string.

What it means

find(CharSequence str, int start) implements substring search within the StringValue. An empty search pattern is meaningless (it would match everywhere), so the method throws IllegalArgumentException('Cannot find empty string.') when str.length() == 0, rather than returning start or -1.

Source

Thrown at flink-core/src/main/java/org/apache/flink/types/StringValue.java:352

     *     <code>-1</code>, if the character sequence was not found.
     */
    public int find(CharSequence str) {
        return find(str, 0);
    }

    /**
     * Finds any occurrence of the <code>str</code> character sequence in this StringValue. The
     * search starts at position <code>start</code>.
     *
     * @return The position of the first occurrence of the search string in the string value, or
     *     <code>-1</code>, if the character sequence was not found.
     */
    public int find(CharSequence str, int start) {
        final int pLen = this.len;
        final int sLen = str.length();

        if (sLen == 0) {
            throw new IllegalArgumentException("Cannot find empty string.");
        }

        int pPos = start;

        final char first = str.charAt(0);

        while (pPos < pLen) {
            if (first == this.value[pPos++]) {
                // matching first character
                final int fallBackPosition = pPos;
                int sPos = 1;
                boolean found = true;

                while (sPos < sLen) {
                    if (pPos >= pLen) {
                        // no more characters in string value
                        pPos = fallBackPosition;
                        found = false;

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Skip the search when the pattern is empty: if (pattern.isEmpty()) handle explicitly
  2. Validate delimiter/pattern configuration is non-empty at startup
  3. If you need indexOf semantics for "", special-case it (treat as found at start)

Example fix

// before
int i = sv.find(delimiter, 0); // delimiter == "" -> throws

// after
int i = delimiter.isEmpty() ? -1 : sv.find(delimiter, 0);
Defensive patterns

Strategy: validation

Validate before calling

if (pattern.isEmpty()) {
    return -1; // or handle 'matches everywhere' explicitly
}
return sv.find(pattern, start);

Prevention

When it happens

Trigger: Calling sv.find(pattern, start) with pattern being the empty string "" — e.g. a separator/delimiter variable that ended up empty after parsing or configuration.

Common situations: Splitting on a configurable delimiter where the config supplied an empty value; search patterns built from optional tokens that concatenated to ""; porting code from String.indexOf where "" is legal (returns the index).

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/91bfc2db7725c87c. Report an issue: GitHub.