{"record":{"id":"246da3d6361b0137","repo":"JetBrains/intellij-community","slug":"cannot-bind-field-is-of-primitive-type","errorCode":null,"errorMessage":"Cannot bind: field is of primitive type: ","messagePattern":"Cannot bind: field is of primitive type: ","errorType":"validation","errorClass":"CodeGenerationException","httpStatus":null,"severity":"error","filePath":"java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java","lineNumber":825,"sourceCode":"    public Type getMainClassType() {\n      return Type.getType(\"L\" + myClassName + \";\");\n    }\n\n    private void validateFieldBinding(LwComponent component, final InstrumentationClassFinder.PseudoClass componentClass) throws CodeGenerationException {\n      String binding = component.getBinding();\n      if (binding == null) return;\n\n      validateFieldClass(binding, componentClass, component.getId());\n    }\n\n    private void validateFieldClass(String binding, InstrumentationClassFinder.PseudoClass componentClass, String componentId) throws CodeGenerationException {\n      if (!myFieldDescMap.containsKey(binding)) {\n        throw new CodeGenerationException(componentId, \"Cannot bind: field does not exist: \" + myClassToBind + \".\" + binding);\n      }\n\n      final Type fieldType = Type.getType(myFieldDescMap.get(binding));\n      if (fieldType.getSort() != Type.OBJECT) {\n        throw new CodeGenerationException(componentId, \"Cannot bind: field is of primitive type: \" + myClassToBind + \".\" + binding);\n      }\n\n      try {\n        final InstrumentationClassFinder.PseudoClass fieldClass = myFinder.loadClass(fieldType.getClassName());\n        if (!fieldClass.isAssignableFrom(componentClass)) {\n          throw new CodeGenerationException(componentId, \"Cannot bind: Incompatible types. Cannot assign \" + componentClass.getName().replace('/', '.') + \" to field \" + myClassToBind + \".\" + binding);\n        }\n      }\n      catch (ClassNotFoundException e) {\n        throw new CodeGenerationException(componentId, \"Class not found: \" + fieldType.getClassName());\n      }\n      catch (IOException e) {\n        throw new CodeGenerationException(componentId, e.getMessage(), e);\n      }\n    }\n\n    private void generateBorder(final LwContainer container, final GeneratorAdapter generator, final int componentLocal) {\n      final BorderType borderType = container.getBorderType();","sourceCodeStart":807,"sourceCodeEnd":843,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java#L807-L843","documentation":"Thrown by AsmCodeGenerator.validateFieldClass during GUI-form bytecode instrumentation when a form component is bound to a field whose JVM type descriptor is not an object reference (Type.getSort() != Type.OBJECT). The forms compiler must inject code that assigns the instantiated component to the bound field, and a primitive (or array) field cannot hold a component reference. The message says 'primitive type' but the check actually rejects every non-OBJECT sort, including arrays and primitives.","triggerScenarios":"A .form file has a component with binding='myField' and the class-to-bind declares 'int myField', 'boolean myField', or an array type like 'JButton[] myField'. Instrumentation (AsmCodeGenerator) reads the field descriptor from myFieldDescMap, sees sort != OBJECT, and throws CodeGenerationException with the component id before any assignability check runs.","commonSituations":"Hand-editing a bound class after the form was designed (field refactored from JButton to a primitive/arrays); using the GUI designer's binding field editor against an outdated compiled class where the field signature is stale; forms compiled against an old class version during incremental builds.","solutions":["Change the bound field in the class-to-bind to a reference type compatible with the component (e.g. 'javax.swing.JButton myField;' instead of a primitive or array).","If the field type changed intentionally, re-open the form in the GUI designer, clear or re-point the binding, and rebuild so myFieldDescMap sees fresh field descriptors.","Remove the binding attribute from the component in the .form XML if the field is no longer meant to hold the component.","Run a full rebuild (Build > Rebuild Project) so the forms compiler instruments against current class files rather than stale ones."],"exampleFix":"// before (class to bind)\nprivate int myButton; // form binds component to 'myButton'\n\n// after\nprivate javax.swing.JButton myButton;","handlingStrategy":"validation","validationCode":"// Before instrumenting, verify each binding's field is a reference type\nfor (Field f : classToBind.getDeclaredFields()) {\n  if (bindings.contains(f.getName()) && (f.getType().isPrimitive() || f.getType().isArray())) {\n    throw new IllegalStateException(\"Binding '\" + f.getName() + \"' must be a reference type, was: \" + f.getType());\n}","typeGuard":null,"tryCatchPattern":"try { generator.compile(); } catch (CodeGenerationException e) { if (e.getMessage().contains(\"primitive type\")) { /* fix field type, report component id */ } else throw e; }","preventionTips":["Create bound fields via the GUI designer's 'Create Field' action so types always match the component.","After refactoring bound classes, rebuild fully so the forms compiler sees current field descriptors.","Never bind components to primitive or array-typed fields."],"tags":["gui-designer","forms-compiler","bytecode","binding","class-parse"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}