API Exception Handling
Exceptions are the main problems often encountered in the development process. Here are some common exceptions that may be encountered during the use of
YukiReflection
and how to deal with them.
The exception description here will only synchronize the latest API version, and the exception of the older API version will not be described again, please always keep the API version up-to-date.
Non-Blocking Exceptions
These exceptions will not cause the app to stop running (FC), but will print
E
level logs on the console, and may also stop continuing to execute related functions.
exception
loggerE
Method/Constructor/Field match type "TYPE" not allowed
Abnormal
A disallowed parameter type was set when looking up methods, constructors, and variables.
The following example
// Find a method
method {
// Invalid type example is set
param(false, 1, 0)
// Invalid type example is set
returnType = false
}
// Find a variable
field {
// Invalid type example is set
type = false
}
Solution
In the search, param
, returnType
, type
only accept Class
, String
, VariousClass
types, and parameter instances cannot be passed in.
The following example
// Find a method
method {
// ✅ Examples of correct usage
param(BooleanType, IntType, IntType)
// ✅ Examples of correct usage
returnType = BooleanType
// ✅ The following scheme is also correct
returnType = "java.lang.Boolean"
}
// Find a variable
field {
// ✅ Examples of correct usage
type = BooleanType
}
exception
loggerE
NoSuchMethod/NoSuchConstructor/NoSuchField happend in [NAME]
Abnormal
The target method, constructor, and variable were not found when looking for methods, constructors, and variables.
Solution
Please confirm that your search criteria can correctly match the specified methods, constructors and variables in the target Class
.
exception
loggerE
Trying COUNT times and all failure by RemedyPlan
Abnormal
When using RemedyPlan
to search for methods, constructors, and variables, the methods, constructors, and variables are still not found.
Solution
Please confirm the RemedyPlan
parameter you set and the Class
that exists in the current app, and try again.
exception
loggerE
Can't find this Class in [CLASSLOADER]: CONTENT Generated by YukiReflection#ReflectionTool
Abnormal
The Class
object to be searched for was not found via ClassLoader.searchClass
.
The following example
customClassLoader?.searchClass {
from(...)
// ...
}.get()
Solution
This is a security exception, please check the conditions you set, use the relevant tools to view the Class
and bytecode object characteristics in the Dex and try again.
exception
loggerE
Can't find this Method/Constructor/Field in [CLASS]: CONTENT Generated by YukiReflection#ReflectionTool
Abnormal
The methods, constructors, and variables that need to be found cannot be found by specifying conditions.
The following example
TargetClass.method {
name = "test"
param(BooleanType)
}
Solution
This is a security exception, please check the conditions you set, use the relevant tools to view the bytecode object characteristics in the Class
, and try again.
exception
loggerE
The number of VagueType must be at least less than the count of paramTypes
Abnormal
Incorrect use of VagueType
in Method
, Constructor
lookup conditions.
The following example
TargetClass.method {
name = "test"
// <Scenario 1>
param(VagueType)
// <Scenario 2>
param(VagueType, VagueType ...)
}
Solution
VagueType
cannot be completely filled in method and constructor parameters. If there is such a requirement, please use paramCount
.
exception
loggerE
Field match type class is not found
Abnormal
An instance of Class
for type
was not found in the lookup criteria set when looking up the variable.
The following example
field {
name = "test"
// Assume that the Class of the type set here does not exist
type = "com.example.TestClass"
}
Solution
Please check if Class
of type
in the lookup condition exists and try again.
exception
loggerE
Method match returnType class is not found
Abnormal
An instance of Class
of returnType
was not found in the search criteria set when looking up the method.
The following example
method {
name = "test"
// Assume that the Class of returnType set here does not exist
returnType = "com.example.TestClass"
}
Solution
Please check if Class
of returnType
in the lookup condition exists and try again.
exception
loggerE
Method/Constructor match paramType[INDEX] class is not found
Abnormal
The Class
instance subscripted by the index
number of param
was not found in the search conditions set when searching for methods and constructors.
method {
name = "test"
// Assume that the Class with subscript "No.1" set here does not exist
param(StringClass, "com.example.TestClass", BooleanType)
}
Solution
Please check if the Class
subscripted by the index
number of param
in the lookup condition exists and try again.
Blocking Exceptions
These exceptions will directly cause the app to stop running (FC), at the same time print
E
level logs on the console.
exception
NoClassDefFoundError
Can't find this Class in [CLASSLOADER]: CONTENT Generated by YukiReflection#ReflectionTool
Abnormal
The Class
object you were looking for was not found via String.toClass(...)
or classOf<...>()
.
The following example
"com.demo.Test".toClass()
Solution
Please check if the Class
matched by the current string or entity exists in the current ClassLoader
and try again.
exception
IllegalStateException
ClassLoader [CLASSLOADER] is not a DexClassLoader
Abnormal
Use ClassLoader.searchClass
to find Class
but currently ClassLoader
does not extends BaseDexClassLoader
.
Solution
This situation basically does not exist, unless the current app references a Non-ART platform executable (which not realistic) or the current ClassLoader
is null.
exception
IllegalStateException
VariousClass match failed of those CLASSES
Abnormal
All Class
were not found when creating indeterminate Class
objects using VariousClass
.
Solution
After checking whether there is a matching Class
in the current app and try again.
exception
IllegalStateException
paramTypes is empty, please use emptyParam() instead
Abnormal
The empty param
method is preserved when looking up methods, constructors.
The following example
method {
name = "test"
// No parameters are filled in parentheses
param()
}
Solution
To identify this method, the constructor has no parameters, you can have a setter method as follows.
The first way, set emptyParam
(recommended)
The following example
method {
name = "test"
emptyParam()
}
The second way, set paramCount = 0
The following example
method {
name = "test"
paramCount = 0
}
exception
IllegalStateException
Cannot create classes cache for "android", please remove "name" param
Abnormal
The DexClassFinder
cache function searchClass(name = ...)
is used in the System Framework ("android") app.
The following example
searchClass(name = "test") {
from(...)
// ...
}.get()
Solution
Since the cache will store the found Class
name in SharedPreferences
, but the data directory does not exist in the System Framework, so please do not use this function in the System Framework.
exception
IllegalStateException
Target Class type cannot cast to TYPE
Abnormal
Wrong type declared when converting string class name to target Class
using Class.toClass
, Class.toClassOrNull
, GenericClass.argument
methods.
The following uses the Class.toClass
method as an example.
The following example
// Assume the target type is Activity but it was wrongly cast to WrongClass type
val clazz = "android.app.Activity".toClass<WrongClass>()
Solution
The following example
// <Solution 1> Fill in the correct type
val clazz1 = "android.app.Activity".toClass<Activity>()
// <Solution 2> Do not fill in the generic declaration
val clazz2 = "android.app.Activity".toClass()
Please ensure that the generic type declared after executing the method is the specified target Class
type, and you do not need to fill in the generic declaration if the target type is not sure.