{"record":{"id":"f0bd2e97f8cf22b3","repo":"quarkusio/quarkus","slug":"don-t-know-how-to-handle-number-class","errorCode":null,"errorMessage":"Don't know how to handle number class ","messagePattern":"Don't know how to handle number class ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/NumberMessageBodyHandler.java","lineNumber":45,"sourceCode":"        String text = readFrom(entityStream, false);\n        // we initially had one provider per number type, but the TCK wants this Number provider to be overridable\n        if ((Class<? extends Number>) type == Byte.class || (Class<? extends Number>) type == byte.class)\n            return Byte.valueOf(text);\n        if ((Class<? extends Number>) type == Short.class || (Class<? extends Number>) type == short.class)\n            return Integer.valueOf(text);\n        if ((Class<? extends Number>) type == Integer.class || (Class<? extends Number>) type == int.class)\n            return Integer.valueOf(text);\n        if ((Class<? extends Number>) type == Long.class || (Class<? extends Number>) type == long.class)\n            return Long.valueOf(text);\n        if ((Class<? extends Number>) type == Float.class || (Class<? extends Number>) type == float.class)\n            return Float.valueOf(text);\n        if ((Class<? extends Number>) type == Double.class || (Class<? extends Number>) type == double.class)\n            return Double.valueOf(text);\n        if ((Class<? extends Number>) type == BigDecimal.class)\n            return new BigDecimal(text);\n        if ((Class<? extends Number>) type == BigInteger.class)\n            return new BigInteger(text);\n        throw new RuntimeException(\"Don't know how to handle number class \" + type);\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":48,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/NumberMessageBodyHandler.java#L27-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nNumber n = client.target(url).request().get(Number.class);\n// after\nString text = client.target(url).request().get(String.class);\nNumber n = text.contains(\".\") ? new BigDecimal(text) : new BigInteger(text);","handlingStrategy":"validation","validationCode":"Set<Class<?>> SUPPORTED = Set.of(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, BigDecimal.class, BigInteger.class);\nif (!SUPPORTED.contains(type)) { throw new IllegalArgumentException(\"Unsupported number entity type: \" + type); }","typeGuard":"boolean isSupportedNumberType(Class<?> type) {\n    return type == Integer.class || type == Long.class || type == Double.class || type == Float.class\n        || type == Short.class || type == Byte.class || type == BigDecimal.class || type == BigInteger.class;\n}","tryCatchPattern":"try {\n    Number n = response.readEntity(BigDecimal.class);\n} catch (RuntimeException e) {\n    // unsupported number type — parse manually\n    BigDecimal n = new BigDecimal(response.readEntity(String.class));\n}","preventionTips":["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"],"tags":["resteasy-reactive","message-body-reader","number","unsupported-type"],"backgroundTag":"unsupported-entity-type","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}