{"record":{"id":"919a8a6b79552e21","repo":"apache/dubbo","slug":"can-not-create-wrapper-for-primitive-type","errorCode":null,"errorMessage":"Can not create wrapper for primitive type: {}","messagePattern":"Can not create wrapper for primitive type: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Wrapper.java","lineNumber":130,"sourceCode":"     * @return Wrapper instance(not null).\n     */\n    public static Wrapper getWrapper(Class<?> c) {\n        return ConcurrentHashMapUtils.computeIfAbsent(WRAPPER_MAP, c, (clazz) -> {\n            while (ClassGenerator.isDynamicClass(clazz)) // can not wrapper on dynamic class.\n            {\n                clazz = clazz.getSuperclass();\n            }\n\n            if (clazz == Object.class) {\n                return OBJECT_WRAPPER;\n            }\n            return makeWrapper(clazz);\n        });\n    }\n\n    private static Wrapper makeWrapper(Class<?> c) {\n        if (c.isPrimitive()) {\n            throw new IllegalArgumentException(\"Can not create wrapper for primitive type: \" + c);\n        }\n\n        String name = c.getName();\n        ClassLoader cl = ClassUtils.getClassLoader(c);\n\n        StringBuilder c1 = new StringBuilder(\"public void setPropertyValue(Object o, String n, Object v){ \");\n        StringBuilder c2 = new StringBuilder(\"public Object getPropertyValue(Object o, String n){ \");\n        StringBuilder c3 =\n                new StringBuilder(\"public Object invokeMethod(Object o, String n, Class[] p, Object[] v) throws \"\n                        + InvocationTargetException.class.getName() + \"{ \");\n\n        c1.append(name)\n                .append(\" w; try{ w = ((\")\n                .append(name)\n                .append(\")$1); }catch(Throwable e){ throw new IllegalArgumentException(e); }\");\n        c2.append(name)\n                .append(\" w; try{ w = ((\")\n                .append(name)","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Wrapper.java#L112-L148","documentation":"Thrown by makeWrapper when the class passed in is a Java primitive type (boolean.class, int.class, etc.). Wrapper generates bytecode to access properties and invoke methods, which is meaningless for primitives, so it rejects them up front.","triggerScenarios":"Calling Wrapper.getWrapper(int.class), Wrapper.getWrapper(boolean.class), or any c.isPrimitive() class directly, or a code path that resolves a field/return type to a primitive .class object and forwards it to getWrapper.","commonSituations":"A reflection utility or serialization layer obtains the raw primitive Class object (e.g. from a field of primitive type) and passes it to getWrapper instead of its wrapper type. Also happens when method return types are inspected incorrectly.","solutions":["Box the primitive before wrapping: use the corresponding wrapper class (Integer.class for int.class) via ClassUtils or manually.","Check c.isPrimitive() before calling getWrapper and route primitives through a different path.","Inspect the calling code that resolves the Class to ensure it uses getReturnType()/getField().getType() correctly rather than a primitive literal."],"exampleFix":"// before\nWrapper w = Wrapper.getWrapper(int.class);  // throws\n// after\nClass<?> c = int.class;\nif (c.isPrimitive()) c = getBoxedType(c);\nWrapper w = Wrapper.getWrapper(c);","handlingStrategy":"validation","validationCode":"Class<?> c = someClass;\nif (c.isPrimitive()) {\n    // route primitive types away from Wrapper\n    c = boxPrimitive(c); // or skip wrapping\n}\nWrapper w = Wrapper.getWrapper(c);","typeGuard":"static boolean isWrapperSafe(Class<?> c) {\n    return !c.isPrimitive();\n}","tryCatchPattern":"try {\n    Wrapper w = Wrapper.getWrapper(c);\n} catch (IllegalArgumentException e) {\n    // c was primitive; use boxed type or alternate path\n}","preventionTips":["Check isPrimitive() before calling getWrapper.","Box primitive Class objects to their wrapper equivalents before wrapping.","Audit reflection code that resolves Class objects from fields/return types."],"tags":["reflection","bytecode","wrapper","primitive","validation"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}