{"record":{"id":"a7c0187a13d9158c","repo":"stanfordnlp/CoreNLP","slug":"couldn-t-instantiate-categorymerginggrammarcompact","errorCode":null,"errorMessage":"Couldn't instantiate CategoryMergingGrammarCompactor.","messagePattern":"Couldn't instantiate CategoryMergingGrammarCompactor\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/lexparser/GrammarCompactionTester.java","lineNumber":249,"sourceCode":"      }\n    } else if (op.trainOptions.compactGrammar() == 5) {\n      System.out.println(\"Instantiating fsm.CategoryMergingGrammarCompactor\");\n      try {\n        Class[] argTypes = new Class[6];\n        Class strClass = String.class;\n        for (int j = 0; j < argTypes.length; j++) {\n          argTypes[j] = strClass;\n        }\n        Object[] cArgs = new Object[6];\n        cArgs[0] = splitParamString;\n        cArgs[1] = trainThresholdString;\n        cArgs[2] = heldoutThresholdString;\n        cArgs[3] = minArcCostString;\n        cArgs[4] = ignoreUnsupportedSuffixesString;\n        cArgs[5] = smoothParamString;\n        compactor = (GrammarCompactor) Class.forName(\"fsm.CategoryMergingGrammarCompactor\").getConstructor(argTypes).newInstance(cArgs);\n      } catch (Exception e) {\n        throw new RuntimeException(\"Couldn't instantiate CategoryMergingGrammarCompactor.\" + e);\n      }\n    } else if (op.trainOptions.compactGrammar() == 3) {\n      System.out.println(\"Instantiating fsm.ExactGrammarCompactor\");\n      compactor = new ExactGrammarCompactor(op, saveGraphs, true);\n    } else if (op.trainOptions.compactGrammar() > 0) {\n    }\n\n    if (markovOrder >= 0) {\n      op.trainOptions.markovOrder = markovOrder;\n      op.trainOptions.hSelSplit = false;\n    }\n    if (toy) {\n      buildAndCompactToyGrammars();\n    } else {\n      testGrammarCompaction();\n    }\n  }\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/lexparser/GrammarCompactionTester.java#L231-L267","documentation":"GrammarCompactionTester.runTest tries to reflectively instantiate fsm.CategoryMergingGrammarCompactor when compactGrammar() == 2. Because that class lives in an FSM package that is not always shipped/compiled, Class.forName or the constructor fails, and any Exception is rethrown wrapped in this RuntimeException (message includes the underlying cause).","triggerScenarios":"Setting trainOptions.compactGrammar to 2 while fsm.CategoryMergingGrammarCompactor is not on the classpath or its constructor signature/arguments don't match.","commonSituations":"Running grammar compaction tests with a partial build that excludes the fsm classes, or after a version change altered the compactor's constructor arguments.","solutions":["Ensure the fsm jar/classes (CategoryMergingGrammarCompactor) are on the classpath.","Use compactGrammar == 3 (ExactGrammarCompactor) instead, which is bundled in the lexparser codebase.","Check that the six compactor arguments (argTypes/cArgs) still match the constructor for your library version."],"exampleFix":"// before\nop.trainOptions.compactGrammar = 2; // requires external fsm classes\n// after\nop.trainOptions.compactGrammar = 3; // uses bundled ExactGrammarCompactor","handlingStrategy":"try-catch","validationCode":"try { Class.forName(\"fsm.CategoryMergingGrammarCompactor\"); }\ncatch (ClassNotFoundException e) { /* fall back to ExactGrammarCompactor (compactGrammar=3) */ }","typeGuard":null,"tryCatchPattern":"try { runTest(); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Couldn't instantiate\")) { op.trainOptions.compactGrammar = 3; } }","preventionTips":["Verify fsm classes are on the classpath before choosing compactGrammar == 2","Prefer the bundled ExactGrammarCompactor unless the category-merging compactor is required"],"tags":["reflection","classpath","grammar-compaction","missing-class"],"backgroundTag":"class-not-found","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"}