I got an unexpected internal NPE when playing with this script.

```
POST _scripts/painless/_execute
{
  "script": {
    "source": """
    return /[^\w]+/.split('abc   def higkln').toArray(String[]::new)
    """
  }
}
```
```
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [ ],
        "script" : "\n    return /[^\\w]+/.split('abc   def higkln').toArray(String[]::new)\n    ",
        "lang" : "painless"
      }
    ],
    "type" : "script_exception",
    "reason" : "compile error",
    "script_stack" : [ ],
    "script" : "\n    return /[^\\w]+/.split('abc   def higkln').toArray(String[]::new)\n    ",
    "lang" : "painless",
    "caused_by" : {
      "type" : "null_pointer_exception",
      "reason" : "Cannot read field \"annotations\" because the return value of \"org.elasticsearch.painless.lookup.PainlessLookup.lookupPainlessClass(java.lang.Class)\" is null"
    }
  },
  "status" : 400
}

```
modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultSemanticAnalysisPhase.java
)
            );
        }
        Location location = userRegexNode.getLocation();
        int regexFlags = 0;
        for (int i = 0; i < flags.length(); ++i) {
            char flag = flags.charAt(i);
            regexFlags |= switch (flag) {
                case 'c' -> Pattern.CANON_EQ;
                case 'i' -> Pattern.CASE_INSENSITIVE;
                case 'l' -> Pattern.LITERAL;
                case 'm' -> Pattern.MULTILINE;
                case 's' -> Pattern.DOTALL;
                case 'U' -> Pattern.UNICODE_CHARACTER_CLASS;
                case 'u' -> Pattern.UNICODE_CASE;
                case 'x' -> Pattern.COMMENTS;
                default -> throw new IllegalArgumentException("invalid regular expression: unknown flag [" + flag + "]");
            };
        }
        Pattern compiled;
        try {
            compiled = Pattern.compile(pattern, regexFlags);
        } catch (PatternSyntaxException pse) {
            throw new Location(location.getSourceName(), location.getOffset() + 1 + pse.getIndex()).createError(
                new IllegalArgumentException(
                    "invalid regular expression: "
                        + "could not compile regex constant ["
                        + pattern
                        + "] with flags ["
                        + flags