{"record":{"id":"0106f11795710403","repo":"Tencent/matrix","slug":"both-of-invoker-and-fieldname-can-not-be-null-or-n","errorCode":null,"errorMessage":"Both of invoker and fieldName can not be null or nil.","messagePattern":"Both of invoker and fieldName can not be null or nil\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/ReflectFiled.java","lineNumber":17,"sourceCode":"package com.tencent.matrix.util;\n\n\n\nimport java.lang.reflect.Field;\n\npublic class ReflectFiled<Type> {\n    private static final String TAG = \"ReflectFiled\";\n    private Class<?> mClazz;\n    private String mFieldName;\n\n    private boolean mInit;\n    private Field mField;\n\n    public ReflectFiled(Class<?> clazz, String fieldName) {\n        if (clazz == null || fieldName == null || fieldName.length() == 0) {\n            throw new IllegalArgumentException(\"Both of invoker and fieldName can not be null or nil.\");\n        }\n        this.mClazz = clazz;\n        this.mFieldName = fieldName;\n    }\n\n    private synchronized void prepare() {\n        if (mInit) {\n            return;\n        }\n        Class<?> clazz = mClazz;\n        while (clazz != null) {\n            try {\n                Field f = clazz.getDeclaredField(mFieldName);\n                f.setAccessible(true);\n                mField = f;\n                break;\n            } catch (Exception e) {\n            }","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/ReflectFiled.java#L1-L35","documentation":"The ReflectFiled constructor throws IllegalArgumentException when the target Class is null or the fieldName is null/empty. ReflectFiled lazily resolves a field by name, so both a class and a non-empty field name are mandatory inputs.","triggerScenarios":"new ReflectFiled(null, \"field\"), new ReflectFiled(Foo.class, null), or new ReflectFiled(Foo.class, \"\") — any construction with missing class or name.","commonSituations":"Field names supplied from configuration or constants that are null/empty at runtime; class references lost after refactoring or proguard changes; building reflective helpers from dynamic input.","solutions":["Pass a concrete Class object and a non-empty field name to the constructor","Validate inputs before constructing ReflectFiled","If the name comes from config, check for null/empty and fall back to a default","Ensure obfuscation (ProGuard/R8) keep rules preserve the target class and field"],"exampleFix":"// before\nReflectFiled f = new ReflectFiled(getFieldClass(), getConfigName()); // may throw\n\n// after\nClass<?> clazz = getFieldClass();\nString name = getConfigName();\nif (clazz != null && name != null && !name.isEmpty()) {\n    ReflectFiled f = new ReflectFiled(clazz, name);\n}","handlingStrategy":"validation","validationCode":"if (clazz == null || fieldName == null || fieldName.isEmpty()) {\n    throw new IllegalArgumentException(\"clazz and fieldName are required\");\n}\nReflectFiled f = new ReflectFiled(clazz, fieldName);","typeGuard":"boolean valid = (clazz != null && fieldName != null && !fieldName.isEmpty());","tryCatchPattern":"try {\n    ReflectFiled f = new ReflectFiled(clazz, fieldName);\n} catch (IllegalArgumentException e) {\n    Log.w(TAG, \"invalid reflect args\", e);\n}","preventionTips":["Validate configuration-derived field names before constructing ReflectFiled","Use constants for field names instead of inline strings","Keep ProGuard rules so class references are not lost or renamed"],"tags":["reflection","android","argument-validation"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}