{"record":{"id":"c53e98a97b8f5952","repo":"stanfordnlp/CoreNLP","slug":"found-option-annotations-in-class","errorCode":null,"errorMessage":"found @Option annotations in class ","messagePattern":"found @Option annotations in class ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/util/ArgumentParser.java","lineNumber":414,"sourceCode":"          canFill.put(name, f);\n          required.put(name, mark);\n          interner.put(name, name);\n          //(add alternate names)\n          if ( ! o.alt().isEmpty()) {\n            for (String alt : o.alt().split(\" *, *\")) {\n              alt = alt.toLowerCase();\n              if (canFill.containsKey(alt) && !alt.equals(name))\n                throw new IllegalArgumentException(\"Multiple declarations of option \" + alt + \": \" + canFill.get(alt) + \" and \" + f);\n              canFill.put(alt, f);\n              if (mark.first) required.put(alt, mark);\n              interner.put(alt, name);\n            }\n          }\n        }\n      }\n      //(check to ensure that something got filled, if any @Option annotation was found)\n      if (someOptionFound && !someOptionFilled) {\n        warn(\"found @Option annotations in class \" + c + \", but didn't set any of them (all options were instance variables and no instance given?)\");\n      }\n    }\n\n    //--Fill Options\n    for (Map.Entry<Object, Object> entry : options.entrySet()) {\n      String rawKeyStr = entry.getKey().toString();\n      String key = rawKeyStr.toLowerCase();\n      // (get values)\n      String value = entry.getValue().toString();\n      assert value != null;\n      Field target = canFill.get(key);\n      // (mark required option as fulfilled)\n      Pair<Boolean, Boolean> mark = required.get(key);\n      if (mark != null && mark.first) {\n        required.put(key, Pair.makePair(true, true));\n      }\n      // (fill the field)\n      if (target != null) {","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/ArgumentParser.java#L396-L432","documentation":"After filling options into a target object, fillOptionsImpl() checks that if the class declared @Option-annotated fields, at least one option was actually filled. If annotations were found but nothing was set (e.g. all options are instance fields but only a static/Class object was passed, or command-line values did not match), it warns 'found @Option annotations in class <c>, but didn't set any of them (all options were instance variables and no instance given?)'. Parsing proceeds, but no options were applied.","triggerScenarios":"Calling fillOptions(Class) instead of fillOptions(instance) when the @Option fields are non-static instance variables; passing a Class object for a class whose options require an instance to be instantiated and populated; flag names on the command line that match none of the @Option names so someOptionFilled stays false while annotations were seen.","commonSituations":"Bootstrapping a pipeline with the wrong class literal; reflection-based instantiation disabled; typos in command-line flags; passing Class.class where a new instance was expected.","solutions":["Pass an instance (or let ArgumentParser instantiate the class) rather than the raw Class object when options are instance fields","Make the @Option fields static if filling into a Class is intended","Verify the command-line flag names match the @Option names exactly","Use the ArgumentParser-produced bootstrap map (getUsage / bootstrapMap) to confirm expected flag names"],"exampleFix":"// before\nArgumentParser.fillOptions(MyOptions.class, args);\n// after\nMyOptions opts = new MyOptions();\nArgumentParser.fillOptions(opts, args);","handlingStrategy":"validation","validationCode":"// ensure an instance is used when @Option fields are non-static\nClass<?> c = MyOptions.class;\nboolean onlyInstanceFields = java.util.Arrays.stream(c.getDeclaredFields())\n    .anyMatch(fd -> fd.isAnnotationPresent(edu.stanford.nlp.util.ArgumentParser.Option.class)\n                 && !java.lang.reflect.Modifier.isStatic(fd.getModifiers()));\nObject target = onlyInstanceFields ? c.getDeclaredConstructor().newInstance() : c;\nArgumentParser.fillOptions(target, args);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer filling into instances unless options are static","Cross-check flag names against getUsage()/bootstrapMap output before running","Keep a smoke test that fills one option per annotated class"],"tags":["java","reflection","options","command-line"],"backgroundTag":"missing-required-option","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}