quarkusio/quarkus · error · IllegalArgumentException

Invalid regex pattern '<stringValue>' in <annotation>: <e.ge

Error message

Invalid regex pattern '<stringValue>' in <annotation>: <e.getMessage()>

What it means

Lookup conditions (@LookupCondition/@LookupNotCondition style annotations) can match strings by REGEX. validateRegex compiles the pattern at build time and wraps any PatternSyntaxException in an IllegalArgumentException including the annotation, the bad pattern and the regex error message.

Source

Thrown at extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/LookupConditionsProcessor.java:258

            }
        }));
    }

    private static StringValueMatch getMatch(AnnotationInstance annotation) {
        AnnotationValue matchValue = annotation.value(MATCH);
        if (matchValue != null) {
            return StringValueMatch.valueOf(matchValue.asEnum());
        }
        return StringValueMatch.EQ;
    }

    private static void validateRegex(AnnotationInstance annotation) {
        if (getMatch(annotation) == StringValueMatch.REGEX) {
            String stringValue = annotation.value(STRING_VALUE).asString();
            try {
                Pattern.compile(stringValue);
            } catch (PatternSyntaxException e) {
                throw new IllegalArgumentException(
                        "Invalid regex pattern '" + stringValue + "' in " + annotation + ": " + e.getMessage(), e);
            }
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Fix the regex in the annotation's stringValue attribute
  2. Test the pattern with Pattern.compile() in a scratch main or unit test
  3. Use StringValueMatch.EQUALS or PREFIX instead of REGEX if simple matching suffices

Example fix

// before
@LookupCondition(stringValue = "[com.acme", match = StringValueMatch.REGEX)
// after
@LookupCondition(stringValue = "com\\.acme\\..*", match = StringValueMatch.REGEX)
Defensive patterns

Strategy: validation

Validate before calling

String p = "com\\.acme\\..*";
try { Pattern.compile(p); } catch (PatternSyntaxException e) { throw new IllegalArgumentException("Bad regex in @LookupCondition: " + p, e); }

Try / catch

try {
    app.start();
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Invalid regex pattern")) {
        log.error(e.getMessage()); // fix the annotation's stringValue
    } else throw e;
}

Prevention

When it happens

Trigger: An annotation with match = REGEX whose 'stringValue' attribute is not a compilable regex — e.g. unbalanced parentheses, dangling quantifier, bad character class — declared on a bean or lookup point.

Common situations: Hand-written regex typos in @LookupCondition(value="[foo", match=REGEX); dynamically composed patterns with unescaped user input; patterns written for another regex flavor.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/1fe78c07ab88935b. Report an issue: GitHub.