quarkusio/quarkus · error · RuntimeException
Don't know how to handle number class
Error message
Don't know how to handle number class
What it means
NumberMessageBodyHandler.doReadFrom throws a RuntimeException when the requested entity type is not one of the Number subclasses it supports (Byte, Short, Integer, Long, Float, Double, BigDecimal, BigInteger and their primitives). The handler cannot map the response text to an arbitrary number type.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/NumberMessageBodyHandler.java:45
String text = readFrom(entityStream, false);
// we initially had one provider per number type, but the TCK wants this Number provider to be overridable
if ((Class<? extends Number>) type == Byte.class || (Class<? extends Number>) type == byte.class)
return Byte.valueOf(text);
if ((Class<? extends Number>) type == Short.class || (Class<? extends Number>) type == short.class)
return Integer.valueOf(text);
if ((Class<? extends Number>) type == Integer.class || (Class<? extends Number>) type == int.class)
return Integer.valueOf(text);
if ((Class<? extends Number>) type == Long.class || (Class<? extends Number>) type == long.class)
return Long.valueOf(text);
if ((Class<? extends Number>) type == Float.class || (Class<? extends Number>) type == float.class)
return Float.valueOf(text);
if ((Class<? extends Number>) type == Double.class || (Class<? extends Number>) type == double.class)
return Double.valueOf(text);
if ((Class<? extends Number>) type == BigDecimal.class)
return new BigDecimal(text);
if ((Class<? extends Number>) type == BigInteger.class)
return new BigInteger(text);
throw new RuntimeException("Don't know how to handle number class " + type);
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Request a concrete supported type (Integer, Long, Double, BigDecimal, etc.) instead of Number.class or an unsupported subclass
- Read the body as String and parse it yourself for unsupported types
- Register a custom MessageBodyReader for the unsupported number type
Example fix
// before
Number n = client.target(url).request().get(Number.class);
// after
String text = client.target(url).request().get(String.class);
Number n = text.contains(".") ? new BigDecimal(text) : new BigInteger(text); Defensive patterns
Strategy: validation
Validate before calling
Set<Class<?>> SUPPORTED = Set.of(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, BigInteger.class);
if (!SUPPORTED.contains(type)) { throw new IllegalArgumentException("Unsupported number entity type: " + type); } Type guard
boolean isSupportedNumberType(Class<?> type) {
return type == Integer.class || type == Long.class || type == Double.class || type == Float.class
|| type == Short.class || type == Byte.class || type == BigDecimal.class || type == BigInteger.class;
} Try / catch
try {
Number n = response.readEntity(BigDecimal.class);
} catch (RuntimeException e) {
// unsupported number type — parse manually
BigDecimal n = new BigDecimal(response.readEntity(String.class));
} Prevention
- Always request concrete supported Number types, never Number.class or custom subclasses
- Parse manually from String for exotic number types
- Register a custom MessageBodyReader if you need unsupported types
When it happens
Trigger: Requesting an entity as a Number subtype the handler does not cover, e.g. reading a body directly as Number.class or an exotic Number subclass like AtomicInteger.
Common situations: Generic client code that declares Number.class as the response type; custom Number subclasses used as entity types; refactors changing entity types without checking reader support.
Related errors
- Unsupported type: ${rawType.getName()}. Use InputStream, Str
- Invalid character:
- No content
- Illegal type in hierarchy:
- Unsupported client type " + client.getClass()
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/f0bd2e97f8cf22b3.
Report an issue: GitHub.