{"record":{"id":"333b35ee652ce2c6","repo":"xai-org/x-algorithm","slug":"cannot-find-class-s","errorCode":null,"errorMessage":"cannot find class %s","messagePattern":"cannot find class (.+?)","errorType":"validation","errorClass":"SemanticCheckFailure","httpStatus":null,"severity":"error","filePath":"botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java","lineNumber":728,"sourceCode":"      throw new SemanticCheckFailure(\n          String.format(\n              \"class to be imported has to be either a TBase or ThriftStruct: %s.\", clsName)\n      );\n    }\n\n    return Constant.UNIT;\n  }\n\n  private ASTNode toImportAs(CompilerContext context, Tree root) throws SemanticCheckFailure {\n\n    String cls = getFullName(root, root.getChildCount() - 1);\n    String alias = root.getChild(root.getChildCount() - 1).getText();\n\n    Class<?> clazz;\n    try {\n      clazz = ClassCache.forName(cls);\n    } catch (Exception e) {\n      throw new SemanticCheckFailure(\n          String.format(\"cannot find class %s\", cls)\n      );\n    }\n\n\n    if (TBase.class.isAssignableFrom(clazz)) {\n      ThriftType type = Type.thriftOf((Class<? extends TBase>) clazz);\n      context.defineType(type, alias);\n    } else if (ThriftStruct.class.isAssignableFrom(clazz)) {\n      ThriftStructType type = Type.thriftStructOf((Class<? extends ThriftStruct>) clazz);\n      context.defineType(type, alias);\n    } else {\n      throw new SemanticCheckFailure(\n          String.format(\"class to be imported has to be either a TBase or ThriftStruct: %s.\", cls)\n      );\n    }\n\n    return Constant.UNIT;","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java#L710-L746","documentation":"The `importAs` construct requires a fully-qualified class name loadable via ClassCache.forName. The class could not be loaded (ClassNotFoundException or related), so the compiler throws during semantic checking.","triggerScenarios":"`importAs(\"com.twitter.feature.DoesNotExist\", alias)` where the class is missing from the classpath, or the string is not a valid class name (typos, wrong package, unshaded vs shaded names).","commonSituations":"Dependency containing the Thrift struct not on the compiler classpath, refactored/renamed package, class only present in a different artifact version, or running the compiler in an environment with a restricted classloader.","solutions":["Verify the fully-qualified class name spelling and package","Add the artifact containing the class to the compiler's classpath","If packages were relocated/shaded, use the relocated name","Confirm the class exists in the dependency version you compile against"],"exampleFix":"// before\nimportAs(\"com.twitter.feature.OldFeature\", f)\n// after\nimportAs(\"com.twitter.feature.NewFeature\", f)","handlingStrategy":"validation","validationCode":"try { ClassCache.forName(cls); } catch (Exception e) { throw new IllegalArgumentException(\"Unknown class: \" + cls); }","typeGuard":null,"tryCatchPattern":"catch (SemanticCheckFailure e) { if (e.getMessage().contains(\"cannot find class\")) reportMissingDependency(e); else throw e; }","preventionTips":["Add thrift artifacts to the compiler classpath","Run ClassCache.forName checks in config validation before compiling rules"],"tags":["botmaker","classpath","class-not-found","import"],"backgroundTag":"class-not-found","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}