alibaba/ARouter · error · IllegalArgumentException
Unsupported primitive type: <type>
Error message
Unsupported primitive type: <type>
What it means
Thrown by AutowiredProcessor.getBundleGetter when generating code that reads a field from a Bundle via a getter method. The switch over TypeKind primitive types (BYTE, SHORT, INT, LONG, FLOAT, DOUBLE, CHAR, BOOLEAN) has no case for the given kind and falls into the default branch. It indicates an annotated @Autowired field whose type is a primitive (or boxed) kind that the compiler plugin does not know how to read from a Bundle.
Source
Thrown at arouter-compiler/src/main/java/com/alibaba/android/arouter/compiler/processor/AutowiredProcessor.java:252
switch (TypeKind.values()[type]) {
case BOOLEAN:
return "getBoolean";
case BYTE:
return "getByte";
case SHORT:
return "getShort";
case INT:
return "getInt";
case LONG:
return "getLong";
case CHAR:
return "getChar";
case FLOAT:
return "getFloat";
case DOUBLE:
return "getDouble";
default:
throw new IllegalArgumentException("Unsupported primitive type: " + TypeKind.values()[type]);
}
}
/**
* Categories field, find his papa.
*
* @param elements Field need autowired
*/
private void categories(Set<? extends Element> elements) throws IllegalAccessException {
if (CollectionUtils.isNotEmpty(elements)) {
for (Element element : elements) {
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
if (element.getModifiers().contains(Modifier.PRIVATE)) {
throw new IllegalAccessException("The inject fields CAN NOT BE 'private'!!! please check field ["
+ element.getSimpleName() + "] in class [" + enclosingElement.getQualifiedName() + "]");
}
View on GitHub (pinned to 84f451d244)
Solutions
- Change the @Autowired field to a supported type (int, long, boolean, String, Parcelable, Serializable, etc.).
- If a special type is required, remove @Autowired and pass it manually via Intent extras and read it yourself.
- Check the field's declared TypeKind and confirm it is one of BYTE/SHORT/INT/LONG/FLOAT/DOUBLE/CHAR/BOOLEAN handled in getBundleGetter.
Example fix
// before @Autowired volatile char flag; // after @Autowired String flag; // or use a supported primitive like boolean/int
Defensive patterns
Strategy: validation
Validate before calling
// before compiling, audit annotated fields
Set<Class<?>> SUPPORTED = Set.of(int.class, long.class, short.class, byte.class,
char.class, float.class, double.class, boolean.class, String.class);
if (field.isAnnotationPresent(Autowired.class) && !SUPPORTED.contains(field.getType())) {
throw new IllegalStateException("Unsupported @Autowired field type: " + field.getType());
} Prevention
- Only annotate fields of types listed in ARouter's supported injection types.
- Pass complex objects as Serializable or Parcelable.
- Review the field types table when upgrading ARouter versions.
When it happens
Trigger: Annotating an @Autowired field with a type whose TypeKind is not one of the handled primitives (e.g. void, a boxed wrapper resolved to an unexpected kind, or an unusual primitive) so getBundleGetter's switch hits default during annotation processing.
Common situations: Autogenerate injection code for a field type the processor does not explicitly support; upgrading ARouter versions where a new exotic field type is added; generated helper covers Activity with Bundle-based injection.
Related errors
- The fields need autowired from intent, its parent must be ac
- The inject fields CAN NOT BE 'private'!!! please check field
- More than one interceptors use same priority [%d], They are
- The @Route is marked on unsupported class, look at [<type>].
- String.format(tipText, key)
AI-assisted analysis of alibaba/ARouter@84f451d244 (2026-09-06).
Data as JSON: /api/errors/b0385780ad33a9bf.
Report an issue: GitHub.