ErrLookup › Background articles › Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries
Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries
"Type mismatch" errors fire when a value's runtime type doesn't fit what an API, converter or codec declared: from IllegalArgumentException and TypeError to custom guards like FlowableIllegalArgumentException. This article explains where the check lives, why it fires, and how 2,292 records across 150 libraries handle it.
Distilled from 2,292 documented records across 150 repositories.
Background
This family collects 2,292 documented records from 150 repositories, and its shape varies less by language than by where the type check sits. At one end are eager, fail-fast guards thrown at API boundaries: spring-projects/spring-ai rejects an @McpLogging callback whose second parameter is not String at registration time, java-native-access/jna refuses callback parameters that have no native mapping, and apple/pkl raises a type mismatch when a value's class is not a subclass of the module or this type. At the other end are checks deep in decoding paths: SeaQL/sea-orm panics in its PostgreSQL row-decoding when a TIMESTAMP column cannot be decoded as NaiveDateTime, bytebase/bytebase wraps a "failed to scan" error when a row column cannot be scanned into the destination Go variables, and apache/cassandra's collection codecs catch an internal cast failure and rethrow it as InvalidTypeException naming the CQL type, the expected Java class and the actual one.
The exception classes show how libraries layer their own names on top of the platform ones. IllegalArgumentException leads with 271 uses, but flowable/flowable-engine throws FlowableIllegalArgumentException 97 times and Activiti/Activiti throws ActivitiIllegalArgumentException 52 times, each keeping the family recognizable while adding project context. TypeError (60 uses) dominates the Python and JavaScript side: lancedb/lancedb fails when an OpenCLIP query is neither a str nor a PIL Image, and cocoindex-io/cocoindex raises a TypeError when a memo_key transform returns anything but a dict. Downcast-style checks appear too, like spring-security's ClassCastException when an @AuthenticationPrincipal does not match the declared parameter type, and dotnet/machinelearning's InvalidOperationException when a tokenizer is not an EnglishRobertaTokenizer.
From the caller's side, the message is usually the diagnostic: apache/seatunnel names both the actual Java class received and the target column type, Activiti names the field, the declared value type and the expected one, and puppetlabs/puppet's TypeAsserter builds expected-versus-actual descriptions including nested mismatches. Handling across the corpus is dominated by checking before it fires: 1,264 records use type-guards and 879 use validation, against only 136 try-catch and 13 fallback. That skews the practical advice toward coercing inputs before the call rather than catching afterwards.
Severity is almost uniformly error (2,238 of 2,292), with a small warning band like risingwavelabs/risingwave, which logs a warning and silently skips a Turbopuffer row whose primary key type cannot become a document id. Every record in the family now has at least one recorded solution, so the pages are actionable; what differs per library is whether the mismatch is a programming bug to fix at the call site, a schema or wire-format drift to reconcile, or a dropped-data situation to monitor.
Common causes
- Passing the wrong type across a typed API boundary. The most common shape: an argument's runtime type fails an isinstance-style guard or assignability check at entry. Examples include spring-ai's String-only callback parameter, jna's unmappable callback parameter types, and lancedb passing a numpy array where only str or PIL Image is accepted.
- Value fails an instanceof or converter contract. A converter accepts exactly one input type and everything else throws: flowable-engine's converter only accepts Jackson JsonNode variables, sea-orm's decode expects NaiveDateTime and bytebase's row scan fails when a column cannot be decoded into the destination Go variable. The fix is usually to convert or cast before the call.
- Unparameterized or drifted generic collections. Raw-typed collections hide element-type mismatches until a codec serializes them. In apache/cassandra, putting an Integer into what should be a List of String for a list<text> column surfaces as InvalidTypeException only at write time.
- Configuration or annotation values resolving to the wrong type. Declarative inputs carry no compiler check, so the resolved value's type is only tested at use. Activiti field declarations fail when the declared value is not assignable to the delegate field, druid rejects a topN metric field that is neither a string nor the expected object shape, and spring-security fails when a SpEL principal expression returns an unrelated type.
- Duplicate or mixed library versions on the classpath. Two generations of the same library produce distinct types, so a guard for one rejects the other. flowable-engine's converter checks the Jackson 2 JsonNode while downstream code targets Jackson 3, so values built with the wrong mapper fail the check even though they look equivalent.
- Downcast to the wrong concrete implementation. Code written for one implementation downcasts a shared abstraction and panics or throws on any other. rustdesk fails to downcast its custom mouse to UInputMouse, and druid panics when a command carries a different selector than the one unchecked-unwrapped.
What usually fixes it
- Coerce or convert at the boundary: parse strings into the expected type, decode files into the expected object form, or cast ambiguous values in the query or transform before the guarded call.
- Check before you call: use the library's own type-guard or predicate where offered, since type-guards (1,264 records) and validation (879) are how this family is handled across the corpus, far ahead of try-catch (136).
- Read the message for both sides of the mismatch: most of these errors name the actual type received and the expected type, which usually identifies the exact call site or config value to change.
- Align versions and schemas: keep a single library generation on the classpath, recompile against changed schema types, and verify the declared types match what the producer actually emits.
Documented occurrences
- OpenClip supports str or PIL Image as query (lancedb/lancedb)
- Failed to get timestamp (SeaQL/sea-orm)
- #{subject} #{what}, (puppetlabs/puppet)
- Value must be ${articleFor(desired)} ${desired}, not ${articleFor(jwkType)} ${jwkType}. (jwtk/jjwt)
- memo_key transform for **kwargs must return dict, got {type(transformed).__name__} (cocoindex-io/cocoindex)
- host callable error: {message} [class={class_name}, lang={language:?}] (BoundaryML/baml)
- Converter can only convert com.fasterxml.jackson.databind.JsonNode. (flowable/flowable-engine)
- Persisted swap trader does not match restored order (nautechsystems/nautilus_trader)
- Second parameter must be of type String: (spring-projects/spring-ai)
- Callback argument <nativeParamTypes[i]> requires custom type conversion (java-native-access/jna)
- failed to scan (bytebase/bytebase)
- failed to downcast custom mouse to UInputMouse (rustdesk/rustdesk)
- Unsupported convert ${value.getClass()} to Float, typeDefine: ${typeDefine} (apache/seatunnel)
- Unsupported DTO type: (alibaba/spring-ai-alibaba)
- Expected string node (json-path/JsonPath)
- The input tokenizer is not using the EnglishRoberta model. (dotnet/machinelearning)
- Incompatible type set on field declaration '${declaration.getName()}' for class ${target.getClass().getName()}. Declared value has type ${declaration.getValue().getClass().getName()}, while expecting ${field.getType().getName()} (Activiti/Activiti)
- DATA_ERR: The request options are not valid (microg/GmsCore)
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid types in specified arguments, in expression '%s'. (Yalantis/uCrop)
- {} is expected to be an instance of org.apache.hadoop.mapreduce.v2.hs.CachedHistoryStorage (apache/hadoop)
…and 2,272 more across the corpus — use search.
Honest provenance: generated on 2026-09-12 from AI-assisted analysis of the linked records. See how records are made.