{"record":{"id":"d19d7119470d727b","repo":"stanfordnlp/CoreNLP","slug":"error-invalid-direction-type","errorCode":null,"errorMessage":"ERROR: invalid direction type ","messagePattern":"ERROR: invalid direction type ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/AbstractCollinsHeadFinder.java","lineNumber":290,"sourceCode":"        headIdx = findLeftHead(daughterTrees, how);\n        break;\n      case \"leftdis\":\n        headIdx = findLeftDisHead(daughterTrees, how);\n        break;\n      case \"leftexcept\":\n        headIdx = findLeftExceptHead(daughterTrees, how);\n        break;\n      case \"right\":\n        headIdx = findRightHead(daughterTrees, how);\n        break;\n      case \"rightdis\":\n        headIdx = findRightDisHead(daughterTrees, how);\n        break;\n      case \"rightexcept\":\n        headIdx = findRightExceptHead(daughterTrees, how);\n        break;\n      default:\n        throw new IllegalStateException(\"ERROR: invalid direction type \" + how[0] + \" to nonTerminalInfo map in AbstractCollinsHeadFinder.\");\n    }\n\n    // what happens if our rule didn't match anything\n    if (headIdx < 0) {\n      if (lastResort) {\n        // use the default rule to try to match anything except categoriesToAvoid\n        // if that doesn't match, we'll return the left or rightmost child (by\n        // setting headIdx).  We want to be careful to ensure that postOperationFix\n        // runs exactly once.\n        String[] rule;\n        if (how[0].startsWith(\"left\")) {\n          headIdx = 0;\n          rule = defaultLeftRule;\n        } else {\n          headIdx = daughterTrees.length - 1;\n          rule = defaultRightRule;\n        }\n        Tree child = traverseLocate(daughterTrees, rule, false);","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/AbstractCollinsHeadFinder.java#L272-L308","documentation":"Head rules are encoded as arrays whose first element is a direction keyword (left, right, leftdis, rightdis, lefthead, righthead, leftexcept, rightexcept, etc.). traverseLocate switches on that keyword and throws IllegalStateException when how[0] is not one of the recognized direction types, meaning the rule table was populated with an invalid operation string.","triggerScenarios":"A subclass of AbstractCollinsHeadFinder (or code built via tregex/tsurgeon-derived configuration) puts a rule into nonTerminalInfo whose direction element is misspelled or unsupported, and determineHead/traverseLocate then evaluates that rule.","commonSituations":"Typo in a hand-written head rule (e.g. 'leftmost' instead of 'left'); porting rules from another head finder with different keywords; a subclasses' rule array shifted so how[0] holds a category instead of a direction.","solutions":["Fix the direction keyword in the nonTerminalInfo rule to a supported value (left, right, leftdis, rightdis, leftheaddis, rightheaddis, leftexcept, rightexcept, etc.).","Compare against valid keywords in AbstractCollinsHeadFinder's switch (postureLookup) in the same file.","Ensure rule arrays are ordered [direction, ...categories] with no off-by-one shift."],"exampleFix":"// before\nnonTerminalInfo.put(\"NP\", new String[][]{{\"leftmost\", \"NN\", \"NNS\"}});\n// after\nnonTerminalInfo.put(\"NP\", new String[][]{{\"left\", \"NN\", \"NNS\"}});","handlingStrategy":"validation","validationCode":"Set<String> VALID = Set.of(\"left\",\"right\",\"leftdis\",\"rightdis\",\"lefthand\",\"righthand\",\"leftexcept\",\"rightexcept\",\"left\",\"right\"); for (String[] rule : rules) { assert VALID.contains(rule[0]); }","typeGuard":null,"tryCatchPattern":"try { head = hf.determineHead(t, parent); } catch (IllegalStateException e) { throw new ConfigurationException(\"Bad head rule: \" + e.getMessage(), e); }","preventionTips":["Unit-test your head finder rules over all categories in your treebank","Copy direction keywords only from the switch statement in AbstractCollinsHeadFinder","Keep rule arrays strictly ordered [direction, categories...]"],"tags":["java","nlp","parsing","invalid-enum-value"],"backgroundTag":"invalid-enum-value","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"}