ftctechnh / ftc_app

FTC Android Studio project to create FTC Robot Controller app.
759 stars 3.17k forks source link

Encountering a ConcurrentModificationException when @OpModeRegistrar is used on more than one method #392

Open stormymcstorm opened 7 years ago

stormymcstorm commented 7 years ago

I'm having trouble using the OpModeRegistrar annotation. While trying to use it I get a ConcurrentModificationException. While trying to find the error I tried removing the OpModeRegistrar annotation from ConceptRegisterOpModes and everything worked as expected. This leads me to believe that this error occurs because there is more than one method using the OpModeRegistrar annotation. This is the stack trace for the ConcurrentModificationException.

Steps for reproducing

  1. Make a copy of ConceptRegisterOpModes in your TeamCode directory (rename if you see fit)
  2. Install and run the app. Notice how the robot fails to start
  3. View the app logs. This is easiest done using Android Studio's Android Monitor
  4. Comment out the line in ConceptRegisterOpModes containing @OpModeRegistrar
  5. Install and run the app. Notice how the app works just fine now
  6. Make another copy of ConceptRegisterOpModes in your TeamCode directory and name it something different
  7. Install and run the app. Notice how the robot fails to start. This shows that the problem isn't that the OpModeRegistrar is in the FtcRobotController and that is occurs when any two methods are annotated with OpModeRegistrar
gearsincorg commented 7 years ago

Thanks for the detailed analysis.

This used to work, so we'll need to see what's changed.

Phil.

cmacfarl commented 7 years ago

Following the steps outlined by @stormymcstorm I can not reproduce this. @gearsincorg you have any luck?

magneticflux- commented 7 years ago

@cmacfarl Are you sure it wasn't just a fluke? Concurrency issues are notoriously hard to diagnose and reproduce since they could depend on the speed of the device or other complex factors. It's technically possible you just got really unlucky.

cmacfarl commented 7 years ago

Well I'm humble enough to never say never, but I don't believe that this is actually a multiple thread concurrency issue, but rather a modification of a collection while iterating over same.

Note this text here: https://docs.oracle.com/javase/7/docs/api/java/util/ConcurrentModificationException.html

If a single thread issues a sequence of method invocations that violates the contract of an object, the object may throw this exception. For example, if a thread modifies a collection directly while it is iterating over the collection with a fail-fast iterator, the iterator will throw this exception.

The fact that @stormymcstorm was able to reproduce the problem at will and describe it so succinctly indicates that there's a problem somewhere, we just don't yet know what the difference between @stormymcstorm's setup is and mine.

@stormymcstorm are you using 3.4?

stormymcstorm commented 7 years ago

@cmacfarl Yes I am using 3.4. I just tried to reproduce it again myself, and it's no longer throwing. I'm try to figure out what I changed to cause this.

cmacfarl commented 7 years ago

If it happens again can you please post the full log someplace accessible?