{"record":{"id":"6af441c563669d93","repo":"oracle/graal","slug":"bad-pattern","errorCode":null,"errorMessage":"Bad pattern: {}","messagePattern":"Bad pattern: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/model/Properties.java","lineNumber":792,"sourceCode":"         * @param entireMatch whether the matcher should only accept full matches\n         * @param flags flags to use to compile the pattern defined by {@code value}\n         */\n        public RegexpPropertyMatcher(String name, String value, boolean entireMatch, int flags) {\n            if (name == null) {\n                throw new IllegalArgumentException(\"Property name must not be null!\");\n            }\n\n            if (value == null) {\n                throw new IllegalArgumentException(\"Property value pattern must not be null!\");\n            }\n\n            this.name = name;\n            this.entireMatch = entireMatch;\n\n            try {\n                valuePattern = Pattern.compile(value, flags);\n            } catch (PatternSyntaxException e) {\n                throw new IllegalArgumentException(\"Bad pattern: \" + value);\n            }\n        }\n\n        @Override\n        public String getName() {\n            return name;\n        }\n\n        @Override\n        public boolean match(Object p) {\n            String s;\n            if (p == null) {\n                return false;\n            }\n            s = p.toString();\n            Matcher m = valuePattern.matcher(s);\n            return entireMatch ? m.matches() : m.find();\n        }","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/model/Properties.java#L774-L810","documentation":"Properties' pattern-based matcher (PropertyMatcher inner class) compiles the user-supplied value string with Pattern.compile(value, flags). If the string is not a valid java.util.regex, a PatternSyntaxException is caught and rethrown as IllegalArgumentException(\"Bad pattern: ...\") so callers get one exception type for bad property-match specifications.","triggerScenarios":"Constructing a PropertyMatcher (e.g. matching node or graph properties for filtering) with a malformed regex such as \"in(\\d+\" (unbalanced group) or an invalid quantifier; the compile happens in the constructor, so it fails at matcher creation time, not at match time.","commonSituations":"User-typed filter expressions in a graph viewer (filter nodes by name/property); property rules copied from other tools that use a different regex dialect (e.g. Perl-only syntax like possessive or look-behind unsupported forms); unescaped user input used directly as a regex.","solutions":["Fix the regex (balance groups/escapes); validate with Pattern.compile() in a try/catch before constructing the matcher","Use Pattern.quote(literal) when the value is meant to be an exact literal, not a regex","Pre-validate user-entered patterns in the UI and show the PatternSyntaxException message"],"exampleFix":"// before\nnew PropertyMatcher(\"name\", \"in(\\d+\", ...); // IllegalArgumentException: Bad pattern\n\n// after\nString val = java.util.regex.Pattern.quote(userInput); // literal match\nnew PropertyMatcher(\"name\", val, ...);","handlingStrategy":"validation","validationCode":"static String validPatternOrThrow(String p) {\n    try { java.util.regex.Pattern.compile(p); return p; }\n    catch (java.util.regex.PatternSyntaxException e) { throw new IllegalArgumentException(\"Bad pattern: \" + p, e); }\n}","typeGuard":null,"tryCatchPattern":"try { new PropertyMatcher(name, value, flags); } catch (IllegalArgumentException e) { /* surface PatternSyntaxException detail to the user, keep previous filter */ }","preventionTips":["Pre-compile user regexes with Pattern.compile before use","Use Pattern.quote for literal matching","Validate filter input in the UI before constructing matchers"],"tags":["graphio","regex","validation","properties"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}