{"action":"opened","issue":{"url":"https://api.github.com/repos/realm/realm-java/issues/765","labels_url":"https://api.github.com/repos/realm/realm-java/issues/765/labels{/name}","comments_url":"https://api.github.com/repos/realm/realm-java/issues/765/comments","events_url":"https://api.github.com/repos/realm/realm-java/issues/765/events","html_url":"https://github.com/realm/realm-java/issues/765","id":54758100,"number":765,"title":"RealmMigrationNeededException doesn't clear all caches","user":{"login":"cmelchior","id":406066,"avatar_url":"https://avatars.githubusercontent.com/u/406066?v=3","gravatar_id":"","url":"https://api.github.com/users/cmelchior","html_url":"https://github.com/cmelchior","followers_url":"https://api.github.com/users/cmelchior/followers","following_url":"https://api.github.com/users/cmelchior/following{/other_user}","gists_url":"https://api.github.com/users/cmelchior/gists{/gist_id}","starred_url":"https://api.github.com/users/cmelchior/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmelchior/subscriptions","organizations_url":"https://api.github.com/users/cmelchior/orgs","repos_url":"https://api.github.com/users/cmelchior/repos","events_url":"https://api.github.com/users/cmelchior/events{/privacy}","received_events_url":"https://api.github.com/users/cmelchior/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/realm/realm-java/labels/Bug","name":"Bug","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-19T12:29:31Z","updated_at":"2015-01-19T12:29:31Z","closed_at":null,"body":"It looks like following code, doesn't properly clear the Realm cache, resulting in Realms with old schemas to exist which can cause NPE like this:\r\n\r\nCode to reproduce:\r\n```\r\n@Override\r\nprotected void onCreate(Bundle savedInstanceState) {\r\n  super.onCreate(savedInstanceState);\r\n  try {\r\n            realm = Realm.getInstance(this);\r\n        } catch (RealmMigrationNeededException e) {\r\n            Realm.deleteRealmFile(this);\r\n            realm = Realm.getInstance(this);\r\n        }\r\n  realm.allObjects(Person.class).findAll();\r\n}\r\n```\r\n\r\nError:\r\n```\r\nCaused by: java.lang.NullPointerException\r\n                        E      at io.realm.PersonRealmProxy.setName(PersonRealmProxy.java:36)\r\n                        E      at io.realm.examples.intro.IntroExampleActivity.basicCRUD(IntroExampleActivity.java:101)\r\n                        E      at io.realm.examples.intro.IntroExampleActivity.onCreate(IntroExampleActivity.java:59)\r\n                        E      at android.app.Activity.performCreate(Activity.java:5231)\r\n                        E      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)\r\n                        E      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)\r\n```\r\n\r\n\r\n\r\n"}}