Method Call Removal removes calls to methods you specify from all your input classes. Use it for calls that are valuable during development but unwanted in production, such as logging calls.
Method Call Removal removes only the calls. It doesn't remove the methods themselves.
This article explains how Method Call Removal works. To configure it, see Configure Method Call Removal.
How It Works
-
Directly specified classes only. DashO removes only calls to methods on the classes you specify. It doesn't remove calls to the same method name and signature on a subclass, even if the subclass doesn't implement the method, because the JVM resolves inherited methods at runtime. Method Call Removal is therefore most effective on classes marked
final, though that isn't required. - Exact values only. Rules don't support regular expressions in class names, method names, or signatures.
- No exclusions. You can't exclude methods or classes. DashO removes all calls to the specified methods in every input.
Effect on Behavior
DashO removes calls to non-void methods whether or not your code uses the return value. It replaces each removed call with a default value for the method's return type: 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> are all null. This may cause unexpected issues.
DashO doesn't change any bytecode outside the method call, including the expression that contains it.
String[] pathSplitterToRemove(String path) { ... }
...
String message = "First path: " + pathSplitterToRemove(path)[0]; // null array accessIt 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 throw a NullPointerException.
Limitations and Troubleshooting
| Limitation or issue | Details |
| Method Call Removal is unavailable. | Your project uses Android Mode. Configure R8 to remove method calls. |
| Calls through a subclass aren't removed. | DashO removes calls only on the classes you specify, because the JVM resolves inherited methods at runtime. Method Call Removal is most effective on classes marked final. |
A NullPointerException occurs after protection. |
Code uses the null replacement value of a removed call. Remove the rule, or change the code so it doesn't use the result. |
| You need to keep calls in specific classes. | Method Call Removal doesn't support exclusions. It removes calls in every input. |