{"record":{"id":"e47aa1a3c8b6a559","repo":"java-native-access/jna","slug":"property-mutator-name-must-start-with-set-or-set-the","errorCode":null,"errorMessage":"Property Mutator name must start with 'set', or set the anotation 'name' value","messagePattern":"Property Mutator name must start with 'set', or set the anotation 'name' value","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java","lineNumber":545,"sourceCode":"            String methName = method.getName();\n            if (methName.startsWith(\"get\")) {\n                return methName.replaceFirst(\"get\", \"\");\n            } else {\n                throw new RuntimeException(\n                        \"Property Accessor name must start with 'get', or set the anotation 'name' value\");\n            }\n        } else {\n            return prop.name();\n        }\n    }\n\n    private String getMutatorName(java.lang.reflect.Method method, ComProperty prop) {\n        if (prop.name().isEmpty()) {\n            String methName = method.getName();\n            if (methName.startsWith(\"set\")) {\n                return methName.replaceFirst(\"set\", \"\");\n            } else {\n                throw new RuntimeException(\n                        \"Property Mutator name must start with 'set', or set the anotation 'name' value\");\n            }\n        } else {\n            return prop.name();\n        }\n    }\n\n    private String getMethodName(java.lang.reflect.Method method, ComMethod meth) {\n        if (meth.name().isEmpty()) {\n            String methName = method.getName();\n            return methName;\n        } else {\n            return meth.name();\n        }\n    }\n\n    @SuppressWarnings(\"deprecation\")\n    protected DISPID resolveDispId(String name) {","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/COM/util/ProxyObject.java#L527-L563","documentation":"This RuntimeException is thrown by ProxyObject.getMutatorName when a @ComProperty-annotated method is used as a property mutator but the annotation's 'name' attribute is empty and the Java method name does not start with 'set'. JNA strips the 'set' prefix to derive the COM property name, so it cannot proceed without either convention or an explicit name.","triggerScenarios":"Declaring a @ComProperty mutator method whose name does not start with 'set' (e.g. 'assignValue(String v)') with no name in the annotation, then invoking it through the COM proxy.","commonSituations":"Custom naming in hand-written COM binding interfaces; refactoring renamed setX to something else; copy-pasted methods annotated as properties without adjusting names.","solutions":["Rename the method to start with 'set' (e.g. setValue)","Set the 'name' attribute of @ComProperty explicitly: @ComProperty(name = \"PropName\")","Check that the property write path (invokePropertyPut) uses getMutatorName on the intended method"],"exampleFix":"// before\n@ComProperty\npublic void assignValue(String value);\n// after\n@ComProperty(name = \"Value\")\npublic void assignValue(String value);","handlingStrategy":"validation","validationCode":"java.lang.reflect.Method m = ...;\nComProperty prop = m.getAnnotation(ComProperty.class);\nif (prop != null && prop.name().isEmpty() && !m.getName().startsWith(\"set\")) {\n    throw new IllegalArgumentException(m.getName() + \" must start with 'set' or set @ComProperty(name=...)\");\n}","typeGuard":"boolean isValidMutator(java.lang.reflect.Method m) {\n    ComProperty p = m.getAnnotation(ComProperty.class);\n    return p == null || (!p.name().isEmpty() || m.getName().startsWith(\"set\"));\n}","tryCatchPattern":null,"preventionTips":["Follow JavaBean naming: setX for mutators of @ComProperty","Specify @ComProperty(name=...) when the method name deviates from the convention","Unit-test COM binding interfaces by invoking each property method early (fail fast at startup, not at call time)"],"tags":["java","com","jna","annotation","naming-convention"],"backgroundTag":"missing-required-argument","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}