java.util.ConcurrentModificationException causes crashes

Added by Torgny Johansson about 4 years ago

Hi!

I'm experiencing quite frequent Android crashes/reboots when developing an AGA app. The problem occurs both when using an emulator and when using a AGA-flashed Nexus 7.

Often (not quite 100% but close to it) when I restart my app, e.g. by doing some changes in Android Studio and then deploying, the tablet will crash/reboot. Checking logcat I see a java.util.ConcurrentModificationException right before the crash and I suspect that is the culprit.

Here is a snippet from logcat:

D/dalvikvm( 6194): GC_FOR_ALLOC freed 4K, 12% free 19926K/22608K, paused 40ms, total 40ms
D/AcornMotiveApplication( 7228): onCreate
D/AgaHandler( 7228): init
D/android.swedspot.automotive.AutomotiveService( 6194): Add new API tube. Current number of tubes: 2
D/AgaHandler( 7228): Register for signals
D/android.swedspot.automotive.AutomotiveService( 6194): Automotive manager not reached: cleaning up
W/dalvikvm( 6194): threadid=22: thread exiting with uncaught exception (group=0x4159eba8)
E/AndroidRuntime( 6194): *** FATAL EXCEPTION IN SYSTEM PROCESS: SocketChannelNBServerSDPNode
E/AndroidRuntime( 6194): java.util.ConcurrentModificationException
E/AndroidRuntime( 6194):     at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
E/AndroidRuntime( 6194):     at java.util.HashMap$KeyIterator.next(HashMap.java:833)
E/AndroidRuntime( 6194):     at com.swedspot.vil.proxy.impl.VilSignalProxyImpl.translateMessage(VilSignalProxyImpl.java:144)
E/AndroidRuntime( 6194):     at com.swedspot.vil.proxy.impl.VilSignalProxyImpl.access$100(VilSignalProxyImpl.java:43)
E/AndroidRuntime( 6194):     at com.swedspot.vil.proxy.impl.VilSignalProxyImpl$1.update(VilSignalProxyImpl.java:83)
E/AndroidRuntime( 6194):     at android.swedspot.sdp.observer.SDPNodeImpl.notify(SDPNodeImpl.java:300)
E/AndroidRuntime( 6194):     at android.swedspot.sdp.observer.SDPNodeImpl.updateForMessageTypeData(SDPNodeImpl.java:442)
E/AndroidRuntime( 6194):     at android.swedspot.sdp.observer.SDPNodeImpl.update(SDPNodeImpl.java:355)
E/AndroidRuntime( 6194):     at android.swedspot.sdp.observer.SDPNodeImpl.notify(SDPNodeImpl.java:300)
E/AndroidRuntime( 6194):     at android.swedspot.sdp.observer.SocketChannelNBServerSDPNode.manageShortMessage(SocketChannelNBServerSDPNode.java:468)
E/AndroidRuntime( 6194):     at android.swedspot.sdp.observer.SocketChannelNBServerSDPNode.manageRead(SocketChannelNBServerSDPNode.java:309)
E/AndroidRuntime( 6194):     at android.swedspot.sdp.observer.SocketChannelNBServerSDPNode.run(SocketChannelNBServerSDPNode.java:140)
E/AndroidRuntime( 6194):     at java.lang.Thread.run(Thread.java:841)
I/Process ( 6194): Sending signal. PID: 6194 SIG: 9
I/ServiceManager(  174): service 'permission' died
I/ServiceManager(  174): service 'hardware' died
I/ServiceManager(  174): service 'sensorservice' died
I/ServiceManager(  174): service 'meminfo' died
I/ServiceManager(  174): service 'power' died

The log "Current api tubes 2" is a bit curious. I only have the one app running but it seems the api tubes is incrementing whenever I restart the app. Is it the number of AutomotiveListeners registered with the service? There doesn't seem to be a way to remove a listener so maybe a stale listener (from previous run) is messing something up? Or am I doing something obviously wrong?

I have not tried developing with just jars and a vanilla android rom but I will try that as well and see what the behaviour is then.


 

Replies (4)

RE: java.util.ConcurrentModificationException causes crashes - Added by Joakim Lundvall about 4 years ago

Hi Torgny,

Thank you for your bug report. I will look into it the beginning of next week and try to reproduce the issue. My guess is that it is incoming signals on the old listener. Took a short look at it today and it should be thread safe but it could be something missed.

I can't imagine that you have done anything wrong. Seems like a strait forward use-case but must have a timing issue. My guess is that the jar-version would work because it encapsulates the proxy within the application and does not share it between apps.

I will come back with a solution as soon as possible.

// Joakim Lundvall

RE: java.util.ConcurrentModificationException causes crashes - Added by Torgny Johansson about 4 years ago

Excellent! Just let me know if you need more logs or any other information.

 

RE: java.util.ConcurrentModificationException causes crashes - Added by Joakim Lundvall about 4 years ago

Hi,

I have commited a fix for this problem today. I will flash a device and test the build tomorrow morning.

// Joakim Lundvall

(1-4/4)