{"record":{"id":"91bfc2db7725c87c","repo":"apache/flink","slug":"cannot-find-empty-string","errorCode":null,"errorMessage":"Cannot find empty string.","messagePattern":"Cannot find empty string\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/StringValue.java","lineNumber":352,"sourceCode":"     *     <code>-1</code>, if the character sequence was not found.\n     */\n    public int find(CharSequence str) {\n        return find(str, 0);\n    }\n\n    /**\n     * Finds any occurrence of the <code>str</code> character sequence in this StringValue. The\n     * search starts at position <code>start</code>.\n     *\n     * @return The position of the first occurrence of the search string in the string value, or\n     *     <code>-1</code>, if the character sequence was not found.\n     */\n    public int find(CharSequence str, int start) {\n        final int pLen = this.len;\n        final int sLen = str.length();\n\n        if (sLen == 0) {\n            throw new IllegalArgumentException(\"Cannot find empty string.\");\n        }\n\n        int pPos = start;\n\n        final char first = str.charAt(0);\n\n        while (pPos < pLen) {\n            if (first == this.value[pPos++]) {\n                // matching first character\n                final int fallBackPosition = pPos;\n                int sPos = 1;\n                boolean found = true;\n\n                while (sPos < sLen) {\n                    if (pPos >= pLen) {\n                        // no more characters in string value\n                        pPos = fallBackPosition;\n                        found = false;","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/StringValue.java#L334-L370","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Skip the search when the pattern is empty: if (pattern.isEmpty()) handle explicitly","Validate delimiter/pattern configuration is non-empty at startup","If you need indexOf semantics for \"\", special-case it (treat as found at start)"],"exampleFix":"// before\nint i = sv.find(delimiter, 0); // delimiter == \"\" -> throws\n\n// after\nint i = delimiter.isEmpty() ? -1 : sv.find(delimiter, 0);","handlingStrategy":"validation","validationCode":"if (pattern.isEmpty()) {\n    return -1; // or handle 'matches everywhere' explicitly\n}\nreturn sv.find(pattern, start);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate delimiter configs are non-empty at startup","Empty pattern is legal for String.indexOf but not here","Special-case empty patterns when porting indexOf-based code"],"tags":["flink","string-value","illegal-argument","search"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}