stanfordnlp/CoreNLP · error · RuntimeException
Exception thrown while scraping fields from
Error message
Exception thrown while scraping fields from
What it means
ArgumentParser's option-name scraping helper reflects over a class's fields to collect @Option names. If reflection (or any step in scrapeFields/annotation lookup) throws, the exception is wrapped in this RuntimeException with the class name appended. It signals the option-holder class itself is unusable for argument parsing.
Solutions
- Fix the underlying exception: this wrapper discards the cause, so reproduce with reflection manually to see the real error.
- Ensure the option-holder class and all its field types are on the classpath (no NoClassDefFoundError).
- Check for restrictive SecurityManager/classloader policies blocking reflection on the class.
- Verify you pass a class that actually declares @Option fields and isn't null/abstract-incompatible.
Example fix
// before
ArgumentParser parser = new ArgumentParser(MyOpts.class, args); // fails if MyOpts fields unloadable
// after
try {
ArgumentParser parser = new ArgumentParser(MyOpts.class, args);
} catch (RuntimeException e) {
throw new IllegalStateException("Check MyOpts class deps/policy: " + e.getMessage(), e);
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check reflectability
MyOpts o = new MyOpts(); // ensures class + field types load
if (o.getClass().getDeclaredFields().length == 0) throw new IllegalStateException("No fields to scrape"); Type guard
boolean isReflectable(Class<?> c) { try { c.getDeclaredFields(); return true; } catch (Throwable t) { return false; } } Try / catch
try { new ArgumentParser(clazz, args); } catch (RuntimeException e) { if (e.getMessage().startsWith("Exception thrown while scraping fields from")) { // reproduce reflection manually to find root cause } throw e; } Prevention
- Ensure all field types of the option class are on the classpath.
- Avoid security policies that block reflection on option classes.
- Instantiate the option class once in a unit test to catch loading issues early.
When it happens
Trigger: ArgumentParser constructor (public) invoked with an option-holder class c whose fields cannot be reflected over — e.g. a security manager blocks setAccessible, annotation scanning fails, or a NoClassDefFoundError from a missing dependency surfaces during field enumeration.
Common situations: Passing a null or non-option class; running under a restrictive classloader/security policy; a field type referenced in the option class comes from a missing jar so field resolution fails.
Related errors
- Cannot create set of holidays.
- Class " + classname + " could not be cast to the correct…
- Error initializing binder
- Illegal path: cp=
- Multiple declarations of option
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/ac1c152fed8df051.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/ArgumentParser.java:739
}
return allProperties;
}
/**
* Return the list of {@link ArgumentParser.Option}'s for provided Class
* @param c The Class to analyze
* @return A List containing the {@link ArgumentParser.Option} names
*/
public static List<String> listOptions(Class c) {
try {
return Arrays.stream(scrapeFields(c)).map(field -> {
ArgumentParser.Option[] anns = field.getAnnotationsByType(ArgumentParser.Option.class);
return (anns.length > 0) ? anns[0].name() : null;
}
).filter(argOpt -> (argOpt != null)).collect(Collectors.toList());
} catch (Exception e) {
throw new RuntimeException("Exception thrown while scraping fields from "+c.getName());
}
}
/**
* Return a string describing the usage of the program this method is called from, given the
* options declared in the given set of classes.
* This will print both the static options, and the non-static options.
*
* @param optionsClasses The classes defining the options being used by this program.
* @return A String describing the usage of the class.
*/
public static String usage(Class[] optionsClasses) {
String mainClass = threadRootClass();
StringBuilder b = new StringBuilder();
b.append("Usage: ").append(mainClass).append(' ');
List<Pair<Option, Field>> options = new ArrayList<>();View on GitHub (pinned to 1b7edd19c4)