Tencent/matrix · error · NoSuchFieldException
Method is not exists.
Error message
Method <fieldName> is not exists.
What it means
ReflectFiled.set() throws NoSuchFieldException with the (mis-worded) message "Method <fieldName> is not exists." when prepare() failed to resolve the requested field and ignoreFieldNoExist is false. It signals that the target class does not declare a field with the configured name.
Solutions
- Correct the field name passed to the ReflectFiled constructor
- Add ProGuard keep rules for the target class/field if obfuscation strips it
- Pass ignoreFieldNoExist=true when the field is optional, then check the boolean return
- Use setWithoutThrow() to swallow the miss and log instead of throwing
- Verify the field exists via clazz.getDeclaredField(name) during development/debugging
Example fix
// before
ReflectFiled<String> f = new ReflectFiled<>(Foo.class, "namme");
f.set(instance, "x", false); // throws
// after
ReflectFiled<String> f = new ReflectFiled<>(Foo.class, "name");
boolean ok = f.set(instance, "x", true);
if (!ok) { MatrixLog.w(TAG, "field missing, skipped"); } Defensive patterns
Strategy: try-catch
Validate before calling
try {
clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
// field missing: fix the name or add keep rules before using set()
} Type guard
boolean fieldExists;
try { clazz.getDeclaredField(fieldName); fieldExists = true; }
catch (NoSuchFieldException e) { fieldExists = false; } Try / catch
try {
reflectFiled.set(instance, value, false);
} catch (NoSuchFieldException e) {
Log.w(TAG, "field not found: " + reflectFiled.getFieldName(), e);
} Prevention
- Pass ignoreFieldNoExist=true for optional fields and check the return value
- Use setWithoutThrow() when absence is acceptable
- Add ProGuard/R8 keep rules for reflected classes and fields
- Verify field names against the exact target class version
When it happens
Trigger: Calling set(instance, value, false) where mFieldName does not exist on the target class — wrong field name, field removed by ProGuard/R8 obfuscation, or field renamed between versions.
Common situations: Typo'd field names; reflecting on obfuscated classes without keep rules; library upgrades renaming private/internal fields; targeting the wrong class in a hierarchy (field declared only in a subclass/superclass).
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Both of invoker and fieldName can not be null or nil.
- unable to cast object
- Both of invoker and fieldName can not be null or nil.
- Method is not exists.
- ---The Proguard mapping file 'mapping.txt' is not legal!
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/76bd9ea565989232.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-android-lib/src/main/java/com/tencent/matrix/util/ReflectFiled.java:127
} catch (IllegalAccessException e) {
MatrixLog.i(TAG, "getWithoutThrow, exception occur :%s", e);
} catch (IllegalArgumentException e) {
MatrixLog.i(TAG, "getWithoutThrow, exception occur :%s", e);
}
return fieldVal;
}
public synchronized boolean set(Object instance, Type val) throws NoSuchFieldException, IllegalAccessException,
IllegalArgumentException {
return set(instance, val, false);
}
public synchronized boolean set(Object instance, Type val, boolean ignoreFieldNoExist)
throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException {
prepare();
if (mField == null) {
if (!ignoreFieldNoExist) {
throw new NoSuchFieldException("Method " + mFieldName + " is not exists.");
}
MatrixLog.w(TAG, String.format("Field %s is no exists.", mFieldName));
return false;
}
mField.set(instance, val);
return true;
}
public synchronized boolean setWithoutThrow(Object instance, Type val) {
boolean result = false;
try {
result = set(instance, val, true);
} catch (NoSuchFieldException e) {
MatrixLog.i(TAG, "setWithoutThrow, exception occur :%s", e);
} catch (IllegalAccessException e) {
MatrixLog.i(TAG, "setWithoutThrow, exception occur :%s", e);
} catch (IllegalArgumentException e) {View on GitHub (pinned to 3b8293bd65)