oracle/graal · error · UnsupportedOperationException

Syntax '{}' not recognized

Error message

Syntax '{}' not recognized

What it means

TruffleFileSystem.getPathMatcher(syntax, pattern) supports exactly 'glob' and 'regex' (case-insensitive); any other syntax string throws UnsupportedOperationException. This matches the FileSystem contract where unrecognized syntaxes are optional, and matches the behavior of the default provider.

Source

Thrown at espresso/src/com.oracle.truffle.espresso.io/src/sun/nio/fs/TruffleFileSystem.java:170

        if (pos <= 0 || pos == syntaxAndPattern.length()) {
            throw new IllegalArgumentException();
        }
        String syntax = syntaxAndPattern.substring(0, pos);
        String input = syntaxAndPattern.substring(pos + 1);

        String expr;
        if (syntax.equalsIgnoreCase(GLOB_SYNTAX)) {
            String os = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
            if (os.contains("win")) {
                expr = sun.nio.fs.Globs.toWindowsRegexPattern(input);
            } else {
                expr = sun.nio.fs.Globs.toUnixRegexPattern(input);
            }
        } else {
            if (syntax.equalsIgnoreCase(REGEX_SYNTAX)) {
                expr = input;
            } else {
                throw new UnsupportedOperationException("Syntax '" + syntax +
                                "' not recognized");
            }
        }

        // return matcher
        final Pattern pattern = compilePathMatchPattern(expr);

        return path -> pattern.matcher(path.toString()).matches();
    }

    @Override
    public UserPrincipalLookupService getUserPrincipalLookupService() {
        throw new UnsupportedOperationException();
    }

    /**
     * We cannot just throw {@link UnsupportedOperationException} since we implement the Default
     * filesystem.

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Use only 'glob:...' or 'regex:...' prefixed patterns.
  2. Translate custom patterns to regex before calling getPathMatcher.
  3. Validate and normalize the syntax prefix from user input before use.

Example fix

// before
PathMatcher m = fs.getPathMatcher("wildcard:*.txt"); // throws

// after
PathMatcher m = fs.getPathMatcher("glob:*.txt");
Defensive patterns

Strategy: validation

Validate before calling

static boolean supportedSyntax(String s) {
    String syntax = s.substring(0, s.indexOf(':')).toLowerCase(Locale.ROOT);
    return syntax.equals("glob") || syntax.equals("regex");
}

Try / catch

try {
    matcher = fs.getPathMatcher(syntaxAndPattern);
} catch (UnsupportedOperationException e) {
    if (e.getMessage().contains("not recognized")) { /* default to glob: */ }
}

Prevention

When it happens

Trigger: Calling FileSystems.getFileSystem(...).getPathMatcher("foo:*") or DirectoryStream filter builders with a custom syntax prefix; also case variations are fine, but e.g. 'GLOB :' with a space or unknown syntax names throw.

Common situations: User-configurable pattern syntax options in tools (allowing 'ant', 'wildcard', etc.); code ported from libraries that registered custom PathMatcher syntaxes on the default provider.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/b26cf66e26f8b93f. Report an issue: GitHub.