String globRegex = globToRegex(cwdPattern, fnmatchFlags, true);
boolean doBraces = (flags & GLOB_BRACE) != 0;  String globRegex = globToRegex(cwdPattern, fnmatchFlags, doBraces);
  private static boolean globImpl(Env env, String pattern, int flags,                                   Path path, String prefix, ArrayValue result)  {    String cwdPattern;    String subPattern = null;    int firstSlash = pattern.indexOf('/');    if (firstSlash < 0)      cwdPattern = pattern;    else {      cwdPattern = pattern.substring(0, firstSlash);      // strip off any extra slashes      for (; firstSlash < pattern.length(); firstSlash++) {        if (pattern.charAt(firstSlash) != '/')          break;      }      subPattern = pattern.substring(firstSlash);    }    int fnmatchFlags = 0;    if ((flags & GLOB_NOESCAPE) != 0)      fnmatchFlags = FNM_NOESCAPE;    String globRegex = globToRegex(cwdPattern, fnmatchFlags, true);    if (globRegex == null)      return false;    Pattern compiledGlobRegex;    try {      compiledGlobRegex = Pattern.compile(globRegex);    } catch (PatternSyntaxException e) {      log.log(Level.FINE, e.toString(), e);      return false;    }    String [] list;    try {      list = path.list();    } catch (IOException e) {      return false;    }    for (String entry : list) {      Matcher matcher = compiledGlobRegex.matcher(entry);      if (matcher.matches()) {        StringBuilderValue sb = new StringBuilderValue();        sb.append(prefix);        if (prefix.length() > 0)          sb.append("/");        sb.append(entry);        Path entryPath = path.lookup(entry);        if (entryPath != null && entryPath.isDirectory()) {          if (firstSlash >= 0 && subPattern.length() > 0) {            // ArrayValue.add only adds values when the argument is an            // actual array            globImpl(env, subPattern, flags, entryPath, sb.toString(), result);          } else if ((flags & GLOB_MARK) != 0) {            sb.append("/");          }        }        if ((firstSlash < 0 || subPattern.length() == 0) &&             (((flags & GLOB_ONLYDIR) == 0) ||             (((flags & GLOB_ONLYDIR) != 0) &&               (entryPath != null && entryPath.isDirectory()))))          result.put(sb);      }    }    if (result.getSize() == 0)      return false;    return true;  }