apache/beam · error · IllegalStateException

Unknown event type +

Error message

Unknown event type + 

What it means

TestStream's coder decode() throws IllegalStateException when it reads an eventType byte that is not one of the known enum values (ELEMENT, WATERMARK, PROCESSING_TIME). This guards wire-format corruption or version skew between encoder and decoder.

Solutions

  1. Decode the TestStream with the same Beam version that encoded it
  2. Re-encode the TestStream after aligning SDK versions
  3. Check the eventType value in the failure and map it to the enum to confirm corruption vs version skew
Defensive patterns

Strategy: try-catch

Try / catch

try {
  TestStream<?> stream = TestStream.CoderHub.decode(bytes);
} catch (IllegalStateException e) {
  if (e.getMessage().startsWith("Unknown event type")) {
    throw new IllegalStateException("TestStream bytes encoded with an incompatible Beam version", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Decoding a TestStream whose encoded event-type discriminant is outside the handled switch cases — typically a stream encoded by a newer/older Beam version with extra event types, or corrupted/incorrectly deserialized bytes.

Common situations: Pipelined data serialized with a different Beam version where TestStream.Encoding evolved; hand-crafted or truncated encoded TestStream data in tests.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/44a39b5e0dba1073. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/testing/TestStream.java:387

        switch (eventType) {
          case ELEMENT:
            int numElements = VarIntCoder.of().decode(inStream);
            List<TimestampedValue<T>> elements = new ArrayList<>(numElements);
            for (int j = 0; j < numElements; j++) {
              elements.add(elementCoder.decode(inStream));
            }
            events.add(ElementEvent.add(elements));
            break;
          case WATERMARK:
            Instant watermark = InstantCoder.of().decode(inStream);
            events.add(WatermarkEvent.advanceTo(watermark));
            break;
          case PROCESSING_TIME:
            Duration duration = DurationCoder.of().decode(inStream).toDuration();
            events.add(ProcessingTimeEvent.advanceBy(duration));
            break;
          default:
            throw new IllegalStateException("Unknown event type + " + eventType);
        }
      }
      return TestStream.fromRawEvents(elementCoder.getValueCoder(), events);
    }

    @Override
    public List<? extends Coder<?>> getCoderArguments() {
      return Collections.singletonList(elementCoder);
    }

    @Override
    public void verifyDeterministic() throws NonDeterministicException {}
  }
}

View on GitHub (pinned to 12126d8942)