stanfordnlp/CoreNLP · error · RuntimeException

No matching files

Error message

No matching files: {baseDir}	{filePattern}

What it means

When building an ObjectBank from a base directory plus a file pattern, makeObjectBankFromString/IO-style scanning collects matching files; if none match, a RuntimeException with the baseDir and pattern is thrown so the caller knows their inputs are wrong rather than silently training/labeling on zero documents.

Solutions

  1. Verify baseDir exists and contains files: new File(baseDir).isDirectory() and list contents
  2. Test the filePattern matching (e.g. Files.walk + matches) before calling
  3. Fix the pattern (e.g. use "\.txt$" regex form if that is what the code expects)
  4. Use an absolute path and confirm the process's working directory

Example fix

// before
ObjectBank<List<CoreLabel>> bank = classifier.makeObjectBankFromString("/wrong/dir", "*.txt");
// after
File dir = new File("/data/corpus");
if (!dir.isDirectory() || dir.listFiles().length == 0) throw new IllegalArgumentException("bad data dir");
ObjectBank<List<CoreLabel>> bank = classifier.makeObjectBankFromString("/data/corpus", ".txt");
Defensive patterns

Strategy: validation

Validate before calling

File dir = new File(baseDir);
if (!dir.isDirectory()) throw new IllegalArgumentException("baseDir is not a directory: " + baseDir);
boolean any = false;
for (File f : dir.listFiles()) if (f.getName().matches(filePattern)) { any = true; break; }
if (!any) throw new IllegalArgumentException("No files match pattern");

Try / catch

try { bank = classifier.makeObjectBankFromString(baseDir, pattern); }
catch (RuntimeException e) { if (e.getMessage().startsWith("No matching files")) { e.printStackTrace(); } throw e; }

Prevention

When it happens

Trigger: Calling makeObjectBankFromString/../makeObjectBank with a baseDir that does not exist, is empty, or a filePattern that matches no files under it.

Common situations: Wrong data directory path (relative vs absolute, wrong working directory); overly restrictive extension pattern (e.g. '*.txt' vs '.txt' files); typo'd glob; data not copied to the deployment environment.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/c2bad2b37efdaee2. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ie/AbstractSequenceClassifier.java:894

  public ObjectBank<List<IN>> makeObjectBankFromFiles(String baseDir, String filePattern,
                                                      DocumentReaderAndWriter<IN> readerAndWriter) {

    File path = new File(baseDir);
    FileFilter filter = new RegExFileFilter(Pattern.compile(filePattern));
    File[] origFiles = path.listFiles(filter);
    Collection<File> files = new ArrayList<>();
    for (File file : origFiles) {
      if (file.isFile()) {
        if (flags.announceObjectBankEntries) {
          log.info("Getting data from " + file + " (" + flags.inputEncoding + " encoding)");
        }
        files.add(file);
      }
    }

    if (files.isEmpty()) {
      throw new RuntimeException("No matching files: " + baseDir + '\t' + filePattern);
    }
    // return new ObjectBank<List<IN>>(new
    // ResettableReaderIteratorFactory(files, flags.inputEncoding),
    // readerAndWriter);
    // TODO get rid of ObjectBankWrapper
    return new ObjectBankWrapper<>(flags, new ObjectBank<>(new ResettableReaderIteratorFactory(files,
            flags.inputEncoding), readerAndWriter), knownLCWords);
  }

  public ObjectBank<List<IN>> makeObjectBankFromFiles(Collection<File> files,
                                                      DocumentReaderAndWriter<IN> readerAndWriter) {
    if (files.isEmpty()) {
      throw new RuntimeException("Attempt to make ObjectBank with empty file list");
    }
    // return new ObjectBank<List<IN>>(new
    // ResettableReaderIteratorFactory(files, flags.inputEncoding),
    // readerAndWriter);
    // TODO get rid of ObjectBankWrapper

View on GitHub (pinned to 1b7edd19c4)