11

I read from http://proguard.sourceforge.net/manual/usage.html about the use of assumenosideeffects. My question refers to the following paragraph:

-assumenosideeffects class_specification Specifies methods that don't have any side effects (other than maybe returning a value). In the optimization step, ProGuard will then remove calls to such methods, if it can determine that the return values aren't used. ProGuard will analyze your program code to find such methods automatically. It will not analyze library code, for which this option can therefore be useful. For example, you could specify the method System.currentTimeMillis(), so that any idle calls to it will be removed. With some care, you can also use the option to remove logging code. Note that ProGuard applies the option to the entire hierarchy of the specified methods. Only applicable when optimizing. In general, making assumptions can be dangerous; you can easily break the processed code. Only use this option if you know what you're doing!

I would need to understand how does ProGuard determine "that the return values aren't used". In particular, if the method calls do not return any value, are they always removed?

Patrick
  • 33,984
  • 10
  • 106
  • 126
Monica Marcus
  • 187
  • 2
  • 10

1 Answers1

11

if the method calls do not return any value, are they always removed?

The answer is Yes. An example is in Chromium sources:

private ChromeBrowserInitializer(Context context) {
    mApplication = (ChromeApplication) context.getApplicationContext();
    mHandler = new Handler(Looper.getMainLooper());
    initLeakCanary();
}

@RemovableInRelease
private void initLeakCanary() {
    // Watch that Activity objects are not retained after their onDestroy() has been called.
    // This is a no-op in release builds.
    LeakCanary.install(mApplication);
}

Methods annotated with @RemovableInRelease will be removed from release builds. chromium_code.flags:

# Remove methods annotated with this if their return value is unused.
-assumenosideeffects class ** {
@org.chromium.base.annotations.RemovableInRelease <methods>;
}
j2ko
  • 2,479
  • 1
  • 16
  • 29