oracle/graal · error · IllegalArgumentException
Bad pattern: {}
Error message
Bad pattern: {} What it means
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.
Source
Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/model/Properties.java:792
* @param entireMatch whether the matcher should only accept full matches
* @param flags flags to use to compile the pattern defined by {@code value}
*/
public RegexpPropertyMatcher(String name, String value, boolean entireMatch, int flags) {
if (name == null) {
throw new IllegalArgumentException("Property name must not be null!");
}
if (value == null) {
throw new IllegalArgumentException("Property value pattern must not be null!");
}
this.name = name;
this.entireMatch = entireMatch;
try {
valuePattern = Pattern.compile(value, flags);
} catch (PatternSyntaxException e) {
throw new IllegalArgumentException("Bad pattern: " + value);
}
}
@Override
public String getName() {
return name;
}
@Override
public boolean match(Object p) {
String s;
if (p == null) {
return false;
}
s = p.toString();
Matcher m = valuePattern.matcher(s);
return entireMatch ? m.matches() : m.find();
}View on GitHub (pinned to a66e9ccd1d)
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
Example fix
// before
new PropertyMatcher("name", "in(\d+", ...); // IllegalArgumentException: Bad pattern
// after
String val = java.util.regex.Pattern.quote(userInput); // literal match
new PropertyMatcher("name", val, ...); Defensive patterns
Strategy: validation
Validate before calling
static String validPatternOrThrow(String p) {
try { java.util.regex.Pattern.compile(p); return p; }
catch (java.util.regex.PatternSyntaxException e) { throw new IllegalArgumentException("Bad pattern: " + p, e); }
} Try / catch
try { new PropertyMatcher(name, value, flags); } catch (IllegalArgumentException e) { /* surface PatternSyntaxException detail to the user, keep previous filter */ } Prevention
- Pre-compile user regexes with Pattern.compile before use
- Use Pattern.quote for literal matching
- Validate filter input in the UI before constructing matchers
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Property count is too big. Properties can contain only
- classForNode method shall return node class representation r
- Unknown type
- File header is missing
- Document properties unexpected in version < 7
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/6af441c563669d93.
Report an issue: GitHub.