Repository: apple/pkl
File: pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java (Java)

Code before:
    public InvalidGlobPatternException(String message) {
      super(message);
    }
  }

  public static final class ResolvedGlobElement {
    private final String path;

    private final URI uri;
    private final boolean isDirectory;

    public ResolvedGlobElement(String path, URI uri, boolean isDirectory) {
      this.path = path;
      this.uri = uri.normalize();
      this.isDirectory = isDirectory;
    }

    public String getPath() {
      return path;
    }

    public URI getUri() {
      return uri;
    }

    public boolean isDirectory() {
      return isDirectory;
    }
  }

  private static final char NULL = 0;

  /**
   * The maximum number of {@link ReaderBase#listElements(SecurityManager, URI)} calls to be made
   * when resolving a glob pattern.
   *
   * <p>The intention is to prevent malicious programs from running, c.f. CVE-2010-2632. Otherwise,
   * a complex glob pattern can starve CPU/memory on a host.
   *
   * <p>Glob limit value taken from <a
   * href="https://github.com/openbsd/src/commit/46df4fe576b7">https://github.com/openbsd/src/commit/46df4fe576b7</a>.
   *
   * <p>If test mode is enabled, a smaller value is used. This greatly speeds up the test that
   * verifies enforcement of the limit (invalidGlobImport6.pkl).
   *
   * <p>Not a static field to prevent compile-time evaluation by native-image.
   */
  private static int maxListElements() {
    return IoUtils.isTestMode() ? 512 : 16384;
  }


Review comment (suggestion):
The util package is not a public API, so no need to add deprecated methods.

```suggestion
  public record ResolvedGlobElement(String path, URI uri, boolean isDirectory) {
  }
```

Code after:
    public InvalidGlobPatternException(String message) {
      super(message);
    }
  }

  public record ResolvedGlobElement(String path, URI uri, boolean isDirectory) {
    public ResolvedGlobElement(String path, URI uri, boolean isDirectory) {
      this.path = path;
      this.uri = uri.normalize();
      this.isDirectory = isDirectory;
    }
  }

  private static final char NULL = 0;

  /**
   * The maximum number of {@link ReaderBase#listElements(SecurityManager, URI)} calls to be made
   * when resolving a glob pattern.
   *
   * <p>The intention is to prevent malicious programs from running, c.f. CVE-2010-2632. Otherwise,
   * a complex glob pattern can starve CPU/memory on a host.
   *
   * <p>Glob limit value taken from <a
   * href="https://github.com/openbsd/src/commit/46df4fe576b7">https://github.com/openbsd/src/commit/46df4fe576b7</a>.
   *
   * <p>If test mode is enabled, a smaller value is used. This greatly speeds up the test that
   * verifies enforcement of the limit (invalidGlobImport6.pkl).
   *
   * <p>Not a static field to prevent compile-time evaluation by native-image.
   */
  private static int maxListElements() {
    return IoUtils.isTestMode() ? 512 : 16384;
  }

  private static final Map<String, Pattern> patterns =
      Collections.synchronizedMap(new WeakHashMap<>());

  private static char getNextChar(String pattern, int i) {
    if (i >= pattern.length() - 1) {
      return NULL;
    }
    return pattern.charAt(i + 1);
  }

  private static int consumeCharacterClass(String globPattern, int idx, StringBuilder sb)
      throws InvalidGlobPatternException {
    // don't match path separators
    sb.append("[[^/]&&[");
    var i = idx;
    switch (getNextChar(globPattern, i)) {
      case '^' -> {