google/agera

[Question] WorkerHandler doesn't extend Handler

bmonjoie opened this issue · 5 comments

I have cloned this repository and, when I try to compile it, I have an error telling me that WorkerHandler doesn't extend Handler.
I have looked into it a little bit and I found out my problem comes from the keyword "final" before the argument "message" in the "handleMessage" method.
One of the errors I have in Android Studio is :

Error:(113, 5) error: method does not override or implement a method from a supertype

If I remove the final keyword, it compiles just fine.

I thought this might have something to do with Java 8 so I install Java 7 and update my alternative to use Java 7 but I have the same error.

Here is a link to a pastebin with the result of my gradle assemble command from a freshly cloned copy : http://pastebin.com/Bss5XuwR

I have asked around me for other people to try to compile and they manage to do it just fine.

I'm running on Ubuntu 15.04 and I have tried with the following java version :

  • 1.7.0_79
  • 1.8.0_66
  • 1.8.0_91

I'm sorry if this is a stupid question but I would really like to understand why it's happening.

It seems to me this is the root cause:

./agera/agera/src/main/java/com/google/android/agera/Common.java:104: error: cannot find symbol
  static final class WorkerHandler extends Handler {
                                           ^
  symbol:   class Handler
  location: class Common

Some setup went wrong or you accidentally removed the import of android.os.Handler?

The final keyword on a parameter does not change the signature of a method; it only affects whether the body of that method can change the value of that parameter.

Also, Android Studio should fully support Java 8 by now.

I understand the confusion but as you can see in the pastebin, I haven't changed anything, it comes from the repository directly. The error telling me that the problem is from the handleMessage method is not shown in the pastebin because it doesn't print in the command line but in Android Studio.

I know that the final keyword doesn't change the signature of the method that why I don't understand.

Edit
Here is a video of the problem I have : https://drive.google.com/file/d/0B0OMKS677lusMDRGOE8yOVpHZ1U/view?usp=sharing

I think I figured out the problem. What was solving the problem was not the removal of final but my Android Studio plugin which was optimizing the import. While optimizing the import, it would reorganize them and put import android.os.Handler at the top of the list.

After some more testing, it seems that import android.os.Handler needs to be above import com.google.android.agera.BaseObservable.Worker because Worker has a reference to WorkerHandler and I guess that it is treated before the import android.os.Handler and that's why it cannot find the symbol.

Sorry for wasting your time on this.

Import statement ordering should not matter either, at least per Java specification..... If your issue is fixed by reordering imports, I think something deeper down is broken...

I had the same problem mentioned above and strangely enough changing the order the import statements did the trick.