apache/skywalking · error · IllegalArgumentException

def cast type not found on classpath: {castType}

Error message

def cast type not found on classpath: {castType}

What it means

Thrown by TimeBucket.getTimeBucket(long, DownSampling) in the switch default branch when the Downsampling value is not one of Second/Minute/Hour/Day. DownSampling is an enum with exactly those four constants, so in unmodified code the default is unreachable — this is a defensive guard against a new enum constant being added without extending the arithmetic here.

Source

Thrown at oap-server/analyzer/log-analyzer/src/main/java/org/apache/skywalking/oap/log/analyzer/v2/compiler/LALDefCodegen.java:222

    private static Class<?> resolveDefCastType(final String castType) {
        switch (castType) {
            case "String":
                return String.class;
            case "Long":
                return Long.class;
            case "Integer":
                return Integer.class;
            case "Double":
                return Double.class;
            case "Float":
                return Float.class;
            case "Boolean":
                return Boolean.class;
            default:
                try {
                    return Class.forName(castType);
                } catch (ClassNotFoundException e) {
                    throw new IllegalArgumentException(
                        "def cast type not found on classpath: " + castType, e);
                }
        }
    }

    // ==================== Def variable chain codegen ====================

    /**
     * Generates typed method-chain access on a def variable.
     * Uses reflection to resolve each method/field call and track types.
     *
     * @param sb output buffer
     * @param localVar the def variable info (java var name + resolved type)
     * @param chain the chain segments after the variable name
     * @param genCtx codegen context
     */
    static void generateDefVarChain(
            final StringBuilder sb,

View on GitHub (pinned to 102af09b4a)

Solutions

  1. If you extended DownSampling, add the corresponding packed-arithmetic case to the switch in TimeBucket.getTimeBucket
  2. On a stock build, verify no bytecode manipulation or classpath shadowing is injecting a different DownSampling class
  3. Audit which DownSampling value is passed (log it) to confirm it comes from the expected enum class
Defensive patterns

Strategy: try-catch

Validate before calling

boolean supported = downsampling == DownSampling.Second || downsampling == DownSampling.Minute
    || downsampling == DownSampling.Hour || downsampling == DownSampling.Day;

Try / catch

catch (UnexpectedException e) { throw new IllegalStateException("unsupported downsampling: " + downsampling, e); }

Prevention

When it happens

Trigger: Adding a new constant (e.g. a month-tier downsampling) to the DownSampling enum without adding a case to this switch; reflective/serialization tricks that produce an uncached enum-like value.

Common situations: Forking or extending SkyWalking with new downsampling granularities; almost never seen on stock builds because the compiler prevents other values.

Related errors


AI-assisted analysis of apache/skywalking@102af09b4a (2026-08-14). Data as JSON: /api/errors/af96d26e7e8cf1db. Report an issue: GitHub.