xai-org/x-algorithm · error · SemanticCheckFailure

cannot find class %s

Error message

cannot find class %s

What it means

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.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/compiler/Compiler.java:728

      throw new SemanticCheckFailure(
          String.format(
              "class to be imported has to be either a TBase or ThriftStruct: %s.", clsName)
      );
    }

    return Constant.UNIT;
  }

  private ASTNode toImportAs(CompilerContext context, Tree root) throws SemanticCheckFailure {

    String cls = getFullName(root, root.getChildCount() - 1);
    String alias = root.getChild(root.getChildCount() - 1).getText();

    Class<?> clazz;
    try {
      clazz = ClassCache.forName(cls);
    } catch (Exception e) {
      throw new SemanticCheckFailure(
          String.format("cannot find class %s", cls)
      );
    }


    if (TBase.class.isAssignableFrom(clazz)) {
      ThriftType type = Type.thriftOf((Class<? extends TBase>) clazz);
      context.defineType(type, alias);
    } else if (ThriftStruct.class.isAssignableFrom(clazz)) {
      ThriftStructType type = Type.thriftStructOf((Class<? extends ThriftStruct>) clazz);
      context.defineType(type, alias);
    } else {
      throw new SemanticCheckFailure(
          String.format("class to be imported has to be either a TBase or ThriftStruct: %s.", cls)
      );
    }

    return Constant.UNIT;

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Verify the fully-qualified class name spelling and package
  2. Add the artifact containing the class to the compiler's classpath
  3. If packages were relocated/shaded, use the relocated name
  4. Confirm the class exists in the dependency version you compile against

Example fix

// before
importAs("com.twitter.feature.OldFeature", f)
// after
importAs("com.twitter.feature.NewFeature", f)
Defensive patterns

Strategy: validation

Validate before calling

try { ClassCache.forName(cls); } catch (Exception e) { throw new IllegalArgumentException("Unknown class: " + cls); }

Try / catch

catch (SemanticCheckFailure e) { if (e.getMessage().contains("cannot find class")) reportMissingDependency(e); else throw e; }

Prevention

When it happens

Trigger: `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).

Common situations: 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.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/333b35ee652ce2c6. Report an issue: GitHub.