{"action":"created","issue":{"url":"https://api.github.com/repos/google/j2objc/issues/767","repository_url":"https://api.github.com/repos/google/j2objc","labels_url":"https://api.github.com/repos/google/j2objc/issues/767/labels{/name}","comments_url":"https://api.github.com/repos/google/j2objc/issues/767/comments","events_url":"https://api.github.com/repos/google/j2objc/issues/767/events","html_url":"https://github.com/google/j2objc/issues/767","id":166232575,"number":767,"title":"private static field access with reflection?","user":{"login":"kpgalligan","id":68384,"avatar_url":"https://avatars.githubusercontent.com/u/68384?v=3","gravatar_id":"","url":"https://api.github.com/users/kpgalligan","html_url":"https://github.com/kpgalligan","followers_url":"https://api.github.com/users/kpgalligan/followers","following_url":"https://api.github.com/users/kpgalligan/following{/other_user}","gists_url":"https://api.github.com/users/kpgalligan/gists{/gist_id}","starred_url":"https://api.github.com/users/kpgalligan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kpgalligan/subscriptions","organizations_url":"https://api.github.com/users/kpgalligan/orgs","repos_url":"https://api.github.com/users/kpgalligan/repos","events_url":"https://api.github.com/users/kpgalligan/events{/privacy}","received_events_url":"https://api.github.com/users/kpgalligan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-19T02:06:18Z","updated_at":"2016-07-21T20:42:50Z","closed_at":null,"body":"In keeping with the strange reflection issues theme, this fell out of gson testing.\r\n\r\nClass<?> unsafeClass = Class.forName(\"sun.misc.Unsafe\");\r\nField f = unsafeClass.getDeclaredField(\"theUnsafe\");\r\nf.setAccessible(true);\r\nfinal Object unsafe = f.get(null);\r\n\r\nThe 'unsafe' at the end has address 0x0. Using it fails, as you might expect.\r\n\r\nThe gson version is being modified for j2objc specifically, so the workaround was simply referencing Unsafe directly in code rather than from 'Class.forName', but I assume there could be similar issues in other cases.  Will try to add a more general, less obscure example and see if the same issue occurs.\r\n\r\nWorkaround code, for reference:\r\n\r\nfinal Object unsafe = Unsafe.getUnsafe();\r\nClass<?> unsafeClass = unsafe.getClass();\r\n\r\nThat worked fine. In context, it allows gson to inflate classes without a no-arg constructor.\r\n\r\nhttps://github.com/google/gson/blob/master/gson/src/main/java/com/google/gson/internal/UnsafeAllocator.java#L34"},"comment":{"url":"https://api.github.com/repos/google/j2objc/issues/comments/234377878","html_url":"https://github.com/google/j2objc/issues/767#issuecomment-234377878","issue_url":"https://api.github.com/repos/google/j2objc/issues/767","id":234377878,"user":{"login":"tomball","id":2991279,"avatar_url":"https://avatars.githubusercontent.com/u/2991279?v=3","gravatar_id":"","url":"https://api.github.com/users/tomball","html_url":"https://github.com/tomball","followers_url":"https://api.github.com/users/tomball/followers","following_url":"https://api.github.com/users/tomball/following{/other_user}","gists_url":"https://api.github.com/users/tomball/gists{/gist_id}","starred_url":"https://api.github.com/users/tomball/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomball/subscriptions","organizations_url":"https://api.github.com/users/tomball/orgs","repos_url":"https://api.github.com/users/tomball/repos","events_url":"https://api.github.com/users/tomball/events{/privacy}","received_events_url":"https://api.github.com/users/tomball/received_events","type":"User","site_admin":false},"created_at":"2016-07-21T20:42:50Z","updated_at":"2016-07-21T20:42:50Z","body":"This is caused by \"theUnsafe\" getting initialized in the class's +initialize method, but that method not being called. I think the fix is for Class.forName() to invoke the class's +initialize method, and will test it this afternoon."}}
{"actor":{"display_login":"tomball"}}