kostaskougios / cloning

deep clone java objects
Other
591 stars 112 forks source link

Deep cloning of HashMap fails on Android P #75

Closed JoshuaJamesOng closed 6 years ago

JoshuaJamesOng commented 6 years ago

HashMap#getDeclaredFields only returns a subset of fields when running on Android P preview (both on emulator and device).

It's likely that this is a side-effect of https://developer.android.com/preview/restrictions-non-sdk-interfaces. I have raised a request on Google's bug tracker (it's private so can't share link) to remove the restriction, but if denied this library could become deprecated from P onwards.

JoshuaJamesOng commented 6 years ago

Update, the issue is only present in this library if the object being cloned extends HashMap, thus causing the map to be cloned using reflection. Cloning objects that have a HashMap field work correctly.

Closing as extending HashMap isn't exactly best practice, so this issue can be avoided by removing class heirarchy.