{"record":{"id":"ac1c152fed8df051","repo":"stanfordnlp/CoreNLP","slug":"exception-thrown-while-scraping-fields-from","errorCode":null,"errorMessage":"Exception thrown while scraping fields from ","messagePattern":"Exception thrown while scraping fields from ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/ArgumentParser.java","lineNumber":739,"sourceCode":"    }\n    return allProperties;\n  }\n\n  /**\n   * Return the list of {@link ArgumentParser.Option}'s for provided Class\n   * @param c The Class to analyze\n   * @return A List containing the {@link ArgumentParser.Option} names\n   */\n\n  public static List<String> listOptions(Class c) {\n    try {\n      return Arrays.stream(scrapeFields(c)).map(field -> {\n        ArgumentParser.Option[] anns = field.getAnnotationsByType(ArgumentParser.Option.class);\n        return (anns.length > 0) ? anns[0].name() : null;\n      }\n      ).filter(argOpt -> (argOpt != null)).collect(Collectors.toList());\n    } catch (Exception e) {\n      throw new RuntimeException(\"Exception thrown while scraping fields from \"+c.getName());\n    }\n  }\n\n\n  /**\n   * Return a string describing the usage of the program this method is called from, given the\n   * options declared in the given set of classes.\n   * This will print both the static options, and the non-static options.\n   *\n   * @param optionsClasses The classes defining the options being used by this program.\n   * @return A String describing the usage of the class.\n   */\n  public static String usage(Class[] optionsClasses) {\n    String mainClass = threadRootClass();\n    StringBuilder b = new StringBuilder();\n    b.append(\"Usage: \").append(mainClass).append(' ');\n\n    List<Pair<Option, Field>> options = new ArrayList<>();","sourceCodeStart":721,"sourceCodeEnd":757,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/ArgumentParser.java#L721-L757","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nArgumentParser parser = new ArgumentParser(MyOpts.class, args); // fails if MyOpts fields unloadable\n// after\ntry {\n  ArgumentParser parser = new ArgumentParser(MyOpts.class, args);\n} catch (RuntimeException e) {\n  throw new IllegalStateException(\"Check MyOpts class deps/policy: \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":"// pre-check reflectability\nMyOpts o = new MyOpts(); // ensures class + field types load\nif (o.getClass().getDeclaredFields().length == 0) throw new IllegalStateException(\"No fields to scrape\");","typeGuard":"boolean isReflectable(Class<?> c) { try { c.getDeclaredFields(); return true; } catch (Throwable t) { return false; } }","tryCatchPattern":"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; }","preventionTips":["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."],"tags":["reflection","argument-parser","initialization","classloading"],"backgroundTag":"module-init-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"}