{"record":{"id":"077c880c3ce48676","repo":"stanfordnlp/CoreNLP","slug":"error-annotating-file-getabsolutefile","errorCode":null,"errorMessage":"Error annotating ${file.getAbsoluteFile()}","messagePattern":"Error annotating (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/StanfordCoreNLP.java","lineNumber":1402,"sourceCode":"            synchronized (totalErrorAnnotating) {\n              totalErrorAnnotating.incValue(1);\n              // check we've processed or errored on every file, handle tasks to run after last document\n              if ((totalProcessed.intValue() + totalErrorAnnotating.intValue()) == files.size()) {\n                // clear pool if necessary\n                if (clearPool)\n                  GLOBAL_ANNOTATOR_CACHE.clear();\n                // print out timing info\n                if (TIME && pipeline.isPresent() && tim.isPresent())\n                  logTimingInfo(pipeline.get(), tim.get());\n              }\n            }\n\n          } else {\n            // if stopping due to error, make sure to clear the pool\n            if (clearPool) {\n              GLOBAL_ANNOTATOR_CACHE.clear();\n            }\n            throw new RuntimeException(\"Error annotating \" + file.getAbsoluteFile(), ex);\n          }\n        });\n\n      } catch (IOException e) {\n        throw new RuntimeIOException(e);\n      }\n\n    }\n  }\n\n  public void processFiles(final Collection<File> files, int numThreads, boolean clearPool, Optional<Timing> tim) throws IOException {\n    processFiles(null, files, numThreads, clearPool, tim);\n  }\n\n  public void processFiles(final Collection<File> files, boolean clearPool, Optional<Timing> tim) throws IOException {\n    processFiles(files, 1, clearPool, tim);\n  }\n","sourceCodeStart":1384,"sourceCodeEnd":1420,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/StanfordCoreNLP.java#L1384-L1420","documentation":"In the multi-file/batch annotate path (annotateFiles-style), when annotating an input file throws and the run is configured to stop on error (clearPool true), the worker wraps the cause in RuntimeException 'Error annotating <file>'. It identifies which file failed while preserving the underlying exception.","triggerScenarios":"Running pipeline.annotate over a collection/directory of files with -replaceInput/-outputExtension style batch processing; one document makes an annotator throw (e.g. tokenizer or parse failure, malformed encoding, empty/garbage input) and requireException/clearPool is set.","commonSituations":"Batch-annotating a mixed corpus where one file has corrupt encoding or an empty body; out-of-memory or thread-pool issues on huge files; model files missing so an annotator throws on first document.","solutions":["Inspect the cause (ex) attached to the RuntimeException - fix the underlying annotation failure for that file.","Validate/pre-filter input files (non-empty, valid encoding) before batch annotation.","Configure the run to continue on error instead of clearing the pool, and log/skip the bad file.","Increase memory (-Xmx) or split very large files if the cause is resource exhaustion."],"exampleFix":"// before\n// batch annotate crashes whole run on one bad file\npipeline.annotate(files);\n// after\nfor (CoreDocument doc : docs) {\n  try { pipeline.annotate(doc); }\n  catch (Exception e) { log.warn(\"Skipping bad document\", e); }\n}","handlingStrategy":"try-catch","validationCode":"for (File f : inputFiles) {\n  if (!f.isFile() || f.length() == 0) log.warn(\"Skipping empty/invalid file: \" + f);\n}","typeGuard":null,"tryCatchPattern":"try {\n  pipeline.annotate(annotation);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Error annotating \")) {\n    log.error(\"Failed on {} cause {}\", e.getMessage(), e.getCause());\n  } else throw e;\n}","preventionTips":["Always inspect getCause() to find the real annotation failure.","Pre-validate corpus files for encoding and non-empty content.","Size the thread pool and heap appropriately for the largest documents.","Process files one-per-try/catch so a single failure does not kill the batch."],"tags":["java","batch-processing","annotation-failure","file-processing"],"backgroundTag":"api-request-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}