{"action":"created","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/4555","repository_url":"https://api.github.com/repos/realm/realm-java","labels_url":"https://api.github.com/repos/realm/realm-java/issues/4555/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/4555/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/4555/events","html_url":"https://github.com/realm/realm-java/issues/4555","id":224326034,"number":4555,"title":"getDeletionRanges should be empty","user":{"login":"DanteAndroid","id":10005563,"avatar_url":"https://avatars2.githubusercontent.com/u/10005563?v=3","gravatar_id":"","url":"https://api.github.com/users/DanteAndroid","html_url":"https://github.com/DanteAndroid","followers_url":"https://api.github.com/users/DanteAndroid/followers","following_url":"https://api.github.com/users/DanteAndroid/following{/other_user}","gists_url":"https://api.github.com/users/DanteAndroid/gists{/gist_id}","starred_url":"https://api.github.com/users/DanteAndroid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanteAndroid/subscriptions","organizations_url":"https://api.github.com/users/DanteAndroid/orgs","repos_url":"https://api.github.com/users/DanteAndroid/repos","events_url":"https://api.github.com/users/DanteAndroid/events{/privacy}","received_events_url":"https://api.github.com/users/DanteAndroid/received_events","type":"User","site_admin":false},"labels":[{"id":3545600,"url":"https://api.github.com/repos/realm/realm-java/labels/T:Help","name":"T:Help","color":"cc317c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2017-04-26T02:32:09Z","updated_at":"2017-04-27T06:44:26Z","closed_at":null,"body":"The data in Realm are not changed at all, but `changeSet.getDeletionRanges()` and `getInsertionRanges()` is not empty.\r\nCode:\r\n```\r\n @Override\r\n    public void onChange(RealmResults<Image> collection, OrderedCollectionChangeSet changeSet) {\r\n        // `null`  means the async query returns the first time.\r\n        if (changeSet == null) {\r\n            log(\"no change\");\r\n            adapter.notifyDataSetChanged();\r\n            return;\r\n        }\r\n        // For deletions, the adapter has to be notified in reverse order.\r\n //        OrderedCollectionChangeSet.Range[] deletions = changeSet.getDeletionRanges();\r\n //       for (int i = deletions.length - 1; i >= 0; i--) {\r\n //           OrderedCollectionChangeSet.Range range = deletions[i];\r\n //          log(\"notifyItemRangeRemoved from: \" + range.startIndex + \" length: \" + range.length);\r\n //         adapter.notifyItemRangeRemoved(range.startIndex, range.length);\r\n //     }\r\n // I have to comment it out to fix this problem\r\n\r\n        OrderedCollectionChangeSet.Range[] insertions = changeSet.getInsertionRanges();\r\n        for (OrderedCollectionChangeSet.Range range : insertions) {\r\n            log(\"notifyItemRangeInserted from: \" + range.startIndex + \" length: \" + range.length);\r\n            adapter.notifyItemRangeInserted(range.startIndex, range.length);\r\n            if (page == 1) {\r\n                recyclerView.scrollToPosition(0);\r\n            }\r\n        }\r\n\r\n//        OrderedCollectionChangeSet.Range[] modifications = changeSet.getChangeRanges();\r\n//        for (OrderedCollectionChangeSet.Range range : modifications) {\r\n//            log(\"no notifyItemRangeChanged \" + range.startIndex + \" to \" + range.length);\r\n//            adapter.notifyItemRangeChanged(range.startIndex, range.length);\r\n//        }\r\n    }\r\n\r\n```\r\n\r\n\r\n\r\nThis problem happens when:\r\nI refresh the data, the same data is saved into Realm, then `notifyItemRangeRemoved` & `notifyItemRangeInserted` is executed which result in recyclerview's weird behavior.\r\n\r\nYou may want to check out my repository [here](https://github.com/DanteAndroid/Beauty/blob/master/app/src/main/java/com/dante/girls/picture/CustomPictureFragment.java#L306) and [here](https://github.com/DanteAndroid/Beauty/blob/master/app/src/main/java/com/dante/girls/picture/PictureFragment.java#L145)  and [here](https://github.com/DanteAndroid/Beauty/blob/master/app/src/main/java/com/dante/girls/picture/CustomPictureFragment.java#L210)\r\n\r\nRealm Version: `classpath \"io.realm:realm-gradle-plugin:3.0.0\"`"},"comment":{"url":"https://api.github.com/repos/realm/realm-java/issues/comments/297626353","html_url":"https://github.com/realm/realm-java/issues/4555#issuecomment-297626353","issue_url":"https://api.github.com/repos/realm/realm-java/issues/4555","id":297626353,"user":{"login":"DanteAndroid","id":10005563,"avatar_url":"https://avatars2.githubusercontent.com/u/10005563?v=3","gravatar_id":"","url":"https://api.github.com/users/DanteAndroid","html_url":"https://github.com/DanteAndroid","followers_url":"https://api.github.com/users/DanteAndroid/followers","following_url":"https://api.github.com/users/DanteAndroid/following{/other_user}","gists_url":"https://api.github.com/users/DanteAndroid/gists{/gist_id}","starred_url":"https://api.github.com/users/DanteAndroid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanteAndroid/subscriptions","organizations_url":"https://api.github.com/users/DanteAndroid/orgs","repos_url":"https://api.github.com/users/DanteAndroid/repos","events_url":"https://api.github.com/users/DanteAndroid/events{/privacy}","received_events_url":"https://api.github.com/users/DanteAndroid/received_events","type":"User","site_admin":false},"created_at":"2017-04-27T06:44:26Z","updated_at":"2017-04-27T06:44:26Z","body":"@Zhuinden Well, I change to 3.1.3 but the problem still exists."}}
{"actor":{"display_login":"DanteAndroid"}}