{"record":{"id":"21ecd7c703923853","repo":"java-native-access/jna","slug":"unsupported-size-size","errorCode":null,"errorMessage":"Unsupported size: <size>","messagePattern":"Unsupported size: <size>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/IntegerType.java","lineNumber":104,"sourceCode":"            case 2:\n                if (unsigned) {\n                    this.value = value & 0xFFFFL;\n                }\n                truncated = (short) value;\n                this.number = Short.valueOf((short) value);\n                break;\n            case 4:\n                if (unsigned) {\n                    this.value = value & 0xFFFFFFFFL;\n                }\n                truncated = (int) value;\n                this.number = Integer.valueOf((int) value);\n                break;\n            case 8:\n                this.number = Long.valueOf(value);\n                break;\n            default:\n                throw new IllegalArgumentException(\"Unsupported size: \" + size);\n        }\n        if (size < 8) {\n            long mask = ~((1L << (size * 8)) - 1);\n            if ((value < 0 && truncated != value)\n                    || (value >= 0 && (mask & value) != 0)) {\n                throw new IllegalArgumentException(\"Argument value 0x\"\n                        + Long.toHexString(value) + \" exceeds native capacity (\"\n                        + size + \" bytes) mask=0x\" + Long.toHexString(mask));\n            }\n        }\n    }\n\n    @Override\n    public Object toNative() {\n        return number;\n    }\n\n    @Override","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/IntegerType.java#L86-L122","documentation":"IntegerType.setValue throws this IllegalArgumentException when the constructor/fromNative path is given a size (in bytes) that is not 1, 2, 4, or 8. IntegerType backs C integer types (uint8_t, int16_t, etc.) and only supports those native widths.","triggerScenarios":"Constructing a custom IntegerType subclass with new MyIntegerType(size, value) where size is e.g. 3, 16, or 0; calling fromNative with a FromNativeContext specifying an invalid size; a library returning a size outside {1,2,4,8}.","commonSituations":"Hand-written IntegerType subclasses for exotic C types (e.g. 3-byte or 128-bit integers); copy-paste errors in the size argument; custom type mappers supplying wrong sizes.","solutions":["Use size 1, 2, 4, or 8 matching the actual C type (int8/uint8=1, int16=2, int32=4, int64=8).","Fix the subclass constructor super(size) call to a supported width.","For sizes not representable, model with a byte array in a Structure or use Memory directly."],"exampleFix":"// before\nclass UInt24 extends IntegerType { UInt24(int v){ super(3, v); } }\n// after\nclass UInt32 extends IntegerType { UInt32(int v){ super(4, v); } }","handlingStrategy":"validation","validationCode":"static void checkIntegerTypeSize(int size) {\n  if (size != 1 && size != 2 && size != 4 && size != 8)\n    throw new IllegalArgumentException(\"IntegerType size must be 1,2,4, or 8, got \" + size);\n}","typeGuard":null,"tryCatchPattern":"try {\n  IntegerType v = new MyInt(raw, size);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Unsupported size:\")) {\n    throw new IllegalStateException(\"Size \" + size + \" has no IntegerType backing; use 1/2/4/8\", e);\n  }\n  throw e;\n}","preventionTips":["Only subclass IntegerType with sizes 1, 2, 4, or 8.","Match size to the exact C type width (stdint mapping).","Reuse built-in types (BYTE, WORD, DWORD_WORD equivalents, NativeLong) instead of custom subclasses.","Test constructors of custom IntegerType subclasses."],"tags":["jna","integertype","unsupported-size","native-types"],"backgroundTag":"invalid-argument-value","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}