ProGuard optimization also remove #wait() calls

java, multithreading, optimization, proguard

Solution

You appear to be specifying `-assumenosideeffects` options that also match `Object#wait()`. ProGuard then happily removes those calls for you. You probably shouldn't add `-assumenosideeffects` options beyond the ones that are documented in the ProGuard manual.

Problem

When Proguard optimize my application, it seams that all calls to `Object#wait()` are being removed. So that each Thread which should passively wait (until notification) is now actively waiting (100% CPU usage). When the optimizing is shutdown with `-dontoptimize` everything is OK. Has I need the optimization for removing some method with `-assumenosideeffects`, I am searching for what's wrong. Is it possible to preserve all calls to `Object#wait()` to be optimized (removed)? Is there any other solution? EDIT 1: For example this code: ``` @Override public void run() { isRunning = true; try { while (isRunning) { if (parent.isActivate) { parent.updateDriveButtons(); synchronized (this) { wait(1000); } } else { synchronized (this) { // Wait for that the page is activated. Utils.wait(this); } } } } catch (Throwable e) { e.printStackTrace(); } finally { isRunning = false; } } ``` is being replaced by this code (after decompiling the optimized code): `wait()` has been removed and only the synchronize is visible with `monitorenter;` ... `monitorexit;` ``` public final void run() { this.isRunning = true; try { while (this.isRunning) { if (this.parent.isShowing()) { ... monitorenter; monitorexit; continue; } monitorenter; monitorexit; }return; } catch (Throwable localThrowable) { Object Ljava/lang/Object;; return; } finally { this.isRunning = false; } throw localObject1; } ```

Original source