Possible crash when regular expression not matched

Issue #93 resolved
Matthias Schoettle created an issue

Not in all cases an operation stops if the regular expression is not matched. For example, getParameter in ClassViewHandler just calls find() followed by calls to group(...). If the regular expression is not matched, an exception will be thrown.

The current implementations seem to do too much (i.e., pattern matches, then compile, find and then group calls). I think in general (for all usages of pattern matching) the following implementation should be used:

Matcher matcher = Pattern.compile(thePattern).matcher(theString);
if (!matcher.matches) {
    // throw illegal argument exception
}

// do your stuff (i.e., get groups by calling matcher.group(...)

Comments (6)

  1. Matthias Schoettle reporter

    Resolved issue #93: Changed all occurrences of pattern matching to use matcher.matches() to check if the input matches the regexp before calling the group() method.

    → <<cset 7c6dab1a38a1>>

  2. Log in to comment