{"record":{"id":"f216f06bcabc714b","repo":"stanfordnlp/CoreNLP","slug":"use-only-one-of-sentences-or-uselabelkeys","errorCode":null,"errorMessage":"Use only one of -sentences or -useLabelKeys","messagePattern":"Use only one of -sentences or -useLabelKeys","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java","lineNumber":246,"sourceCode":"      } else if (args[argIndex].equalsIgnoreCase(\"-useLabelKeys\")) {\n        useLabelKeys = true;\n        argIndex += 1;\n      } else if (args[argIndex].equalsIgnoreCase(\"-nouseLabelKeys\")) {\n        useLabelKeys = false;\n        argIndex += 1;\n      } else {\n        throw new IllegalArgumentException(\"Unknown argument \" + args[argIndex]);\n      }\n    }\n\n    if (outputFile == null) {\n      throw new IllegalArgumentException(\"-output is required\");\n    }\n    if (sentencesFile == null && !useLabelKeys) {\n      throw new IllegalArgumentException(\"-sentences or -useLabelKeys is required\");\n    }\n    if (sentencesFile != null && useLabelKeys) {\n      throw new IllegalArgumentException(\"Use only one of -sentences or -useLabelKeys\");\n    }\n    if (labelsFile == null) {\n      throw new IllegalArgumentException(\"-labels is required\");\n    }\n\n    ParserGrammar parser = loadParser(parserFile, taggerFile);\n\n    TreeBinarizer binarizer = null;\n    if (binarize) {\n      binarizer = TreeBinarizer.simpleTreeBinarizer(parser.getTLPParams().headFinder(), parser.treebankLanguagePack());\n    }\n\n    Map<String, String> labelMap = readLabelMap(labelsFile, separator, remapLabels);\n\n    List<String> sentences;\n    if (sentencesFile != null) {\n      sentences = readSentences(sentencesFile);\n    } else {","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java#L228-L264","documentation":"The two input modes are mutually exclusive: -sentences parses fresh sentences while -useLabelKeys reads labels directly from existing trees. If both are supplied, main throws IllegalArgumentException(\"Use only one of -sentences or -useLabelKeys\") to prevent ambiguous behavior.","triggerScenarios":"Running main with both -sentences <file> and -useLabelKeys set (e.g. left over from a previous command template plus a newly added -sentences flag).","commonSituations":"Accumulated flags in shell scripts from copy-pasting examples; wrappers that always pass -useLabelKeys; switching input modes without removing the old flag.","solutions":["Remove -sentences or -useLabelKeys so only one input mode is specified","If label keys are wanted, drop the sentences file argument; if parsing sentences, drop -useLabelKeys","Audit wrapper scripts for statically included flags"],"exampleFix":"// before\n// java ParseAndSetLabels -sentences in.txt -useLabelKeys -output o.txt ...\n// after\n// java ParseAndSetLabels -useLabelKeys -output o.txt ...","handlingStrategy":"validation","validationCode":"java.util.List<String> a = java.util.Arrays.asList(args);\nif (a.contains(\"-sentences\") && a.contains(\"-useLabelKeys\")) throw new IllegalArgumentException(\"only one of -sentences / -useLabelKeys allowed\");","typeGuard":null,"tryCatchPattern":"try {\n  ParseAndSetLabels.main(args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Use only one of\")) System.err.println(\"Remove either -sentences or -useLabelKeys\");\n  throw e;\n}","preventionTips":["Treat the two flags as an XOR in wrapper scripts","Clean stale flags when reusing command templates","Add mutual-exclusion checks to launch scripts"],"tags":["java","cli","conflicting-flags"],"backgroundTag":"mutually-exclusive-options","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"}