{"action":"created","issue":{"url":"https://api.github.com/repos/google/j2objc/issues/766","repository_url":"https://api.github.com/repos/google/j2objc","labels_url":"https://api.github.com/repos/google/j2objc/issues/766/labels{/name}","comments_url":"https://api.github.com/repos/google/j2objc/issues/766/comments","events_url":"https://api.github.com/repos/google/j2objc/issues/766/events","html_url":"https://github.com/google/j2objc/issues/766","id":166183736,"number":766,"title":"final instance variables not read in 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-18T20:19:25Z","updated_at":"2016-07-18T22:55:04Z","closed_at":null,"body":"final non-static instance variables that are instantiated directly when declared are not read properly with reflection.\r\n\r\nIn the following example, the field 'value' does not return '5' being read through reflection.\r\n\r\nprivate static class BasicFinal {\r\n    public final long value = 5;\r\n  }\r\n\r\nThe value is translated as a constant, but the code in Field.m that reads the value doesn't deal with this case. The code currently falls into this 'if' block, but doesn't match the next condition, and no value gets set for return.\r\n\r\nhttps://github.com/google/j2objc/blob/master/jre_emul/Classes/java/lang/reflect/Field.m#L114\r\n\r\nFor a workaround, making this value static would probably work in most cases, as this is kind of a nonsense case to begin with. This was for gson, which would ignore non-instance fields, so if you had to make this work, set the value in a default constructor.\r\n\r\nprivate static class BasicFinal {\r\n    public final long value;\r\n    public BasicFinal(){value = 5;}\r\n}\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/google/j2objc/issues/comments/233483501","html_url":"https://github.com/google/j2objc/issues/766#issuecomment-233483501","issue_url":"https://api.github.com/repos/google/j2objc/issues/766","id":233483501,"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-18T22:55:04Z","updated_at":"2016-07-18T22:55:04Z","body":"Keith's comment to j2objc-discuss held the fix:\r\n\r\n> Final primitive instance variables that have a constant value are translated as if they were static constants. (Java does this too) \r\n\r\nSo change ReadRawValue's second test from `if (IsStatic(field))` to `if (IsStatic(field) || IsFinal(field))`, and your test case passes. Keith may want a more rigorous test after reviewing change tomorrow, but it should unblock you until the final fix is promoted.\r\n\r\nThanks for the simple test (the best kind); you'll find it in `jre_emul/Tests/com/google/j2objc/FieldTest.java` with this commit.\r\n"}}
{"actor":{"display_login":"tomball"}}