Method Call Removal
If your project inputs contain calls to methods you do not want to be present in the resulting output, you can use PreEmptive Protection™ DashO™ for Android & Java to remove them. This is particularly useful for calls that are valuable during development but undesirable in production, such as logging calls. Calls to the specified methods will be removed from all input classes; the methods themselves are not removed by Method Call Removal.
Only calls made to methods on directly specified classes will be removed - calls made to the same method name and signature on a subclass of a specified method will not be removed.
This is true even if the subclass does not actually implement the method: resolution of inherited methods is done by the JVM at run-time.
Therefore, although this is not required, this feature is most effective on classes marked final
.
NOTE: DashO's Method Call Removal is unavailable in Android Mode, but when using Android Mode you can configure R8 to perform Method Call Removal.
Configuring Method Call Removal
You can configure method call removal on the Method Call Removal page of the DashO GUI. Unlike the rules for many other features, regular expressions are not supported in the class names, method names or signatures for method call removal rules. Additionally, you cannot exclude any methods or classes from method call removal. All calls to the specified methods in any of the inputs will be removed.
Effect on Behavior
Method call removal affects the behavior of your program. Removing method calls may have subtle side-effects, and this feature should be used with caution.
Removal of non-void method calls is applied regardless of whether or not the return value from the method is actually used.
When non-void method calls are removed, a default value is provided as the result in place of the call.
The value is either zero, false, or null, as appropriate for the method's return type.
For example, replacement results for return types Double
, int[]
, and Set<String>
will all be null
.
This may cause unexpected issues.
Method call removal does not alter bytecode outside of the method call, including the expression containing the call:
String[] pathSplitterToRemove(String path) { ... }
...
String message = "First path: " + pathSplitterToRemove(path)[0]; // null array access
It may not be obvious that the code even does anything with the result:
Double methodCallToRemove() { ... }
...
double ignoredValue = methodCallToRemove(); // unboxing a null
After method call removal (of the two *ToRemove
methods), both of these examples will throw a NullPointerException
.