{"action":"created","issue":{"url":"https://api.github.com/repos/box/box-android-sdk/issues/344","repository_url":"https://api.github.com/repos/box/box-android-sdk","labels_url":"https://api.github.com/repos/box/box-android-sdk/issues/344/labels{/name}","comments_url":"https://api.github.com/repos/box/box-android-sdk/issues/344/comments","events_url":"https://api.github.com/repos/box/box-android-sdk/issues/344/events","html_url":"https://github.com/box/box-android-sdk/issues/344","id":295471134,"number":344,"title":"Getting error while trying to refresh boxSession (once the access token has expired)","user":{"login":"dshbq","id":28395949,"avatar_url":"https://avatars2.githubusercontent.com/u/28395949?v=4","gravatar_id":"","url":"https://api.github.com/users/dshbq","html_url":"https://github.com/dshbq","followers_url":"https://api.github.com/users/dshbq/followers","following_url":"https://api.github.com/users/dshbq/following{/other_user}","gists_url":"https://api.github.com/users/dshbq/gists{/gist_id}","starred_url":"https://api.github.com/users/dshbq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dshbq/subscriptions","organizations_url":"https://api.github.com/users/dshbq/orgs","repos_url":"https://api.github.com/users/dshbq/repos","events_url":"https://api.github.com/users/dshbq/events{/privacy}","received_events_url":"https://api.github.com/users/dshbq/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2018-02-08T11:08:06Z","updated_at":"2018-02-21T03:01:42Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nIn my app, when I'm trying to refresh the boxEnterprise access token once the box token has expired, i get below error and once the token is refreshed (it takes sometime to refresh the token), everything works fine.\r\n\r\nBelow is the error logs:\r\n\r\n`Unable to repair user\r\n                                                               java.util.concurrent.ExecutionException: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference\r\n                                                                   at java.util.concurrent.FutureTask.report(FutureTask.java:94)\r\n                                                                   at java.util.concurrent.FutureTask.get(FutureTask.java:164)\r\n                                                                   at com.box.androidsdk.content.models.BoxSession$BoxSessionRefreshRequest.onSend(BoxSession.java:708)\r\n                                                                   at com.box.androidsdk.content.models.BoxSession$BoxSessionRefreshRequest.onSend(BoxSession.java:691)\r\n                                                                   at com.box.androidsdk.content.requests.BoxRequest.send(BoxRequest.java:190)\r\n                                                                   at com.box.androidsdk.content.BoxFutureTask$1.call(BoxFutureTask.java:38)\r\n                                                                   at com.box.androidsdk.content.BoxFutureTask$1.call(BoxFutureTask.java:31)\r\n                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n                                                                   at com.box.androidsdk.content.models.BoxSession$2.run(BoxSession.java:496)\r\n                                                                Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference\r\n                                                                   at com.box.androidsdk.content.auth.BoxAuthentication$4.call(BoxAuthentication.java:504)\r\n                                                                   at com.box.androidsdk.content.auth.BoxAuthentication$4.call(BoxAuthentication.java:446)\r\n                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)\r\n                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)\r\n                                                                   at java.lang.Thread.run(Thread.java:761)\r\n02-08 16:28:58.239 27721-28460/com.allstate.view E/BoxSession: Unable to repair user\r\n                                                               com.box.androidsdk.content.BoxException: An error occurred while sending the request\r\n                                                                   at com.box.androidsdk.content.requests.BoxRequest.onSend(BoxRequest.java:243)\r\n                                                                   at com.box.androidsdk.content.requests.BoxRequest.send(BoxRequest.java:190)\r\n                                                                   at com.box.androidsdk.content.models.BoxSession$BoxSessionAuthCreationRequest.onSend(BoxSession.java:764)\r\n                                                                   at com.box.androidsdk.content.models.BoxSession$BoxSessionAuthCreationRequest.onSend(BoxSession.java:744)\r\n                                                                   at com.box.androidsdk.content.requests.BoxRequest.send(BoxRequest.java:190)\r\n                                                                   at com.box.androidsdk.content.BoxFutureTask$1.call(BoxFutureTask.java:38)\r\n                                                                   at com.box.androidsdk.content.BoxFutureTask$1.call(BoxFutureTask.java:31)\r\n                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)\r\n                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)\r\n                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)\r\n                                                                   at java.lang.Thread.run(Thread.java:761)`\r\n\r\n\r\nCould you please let me know if I'm doing something wrong.\r\n\r\nHere is the code i tried for refresh the token: \r\n`if (boxSession == null) {    \r\n boxSession = getBoxSession(context);     \r\n return boxSession; \r\n} else if (currentTime > expiryTime) {     \r\nboxSession.refresh();    \r\n return boxSession;\r\n} else {\r\nreturn boxSession;\r\n}`\r\n\r\nI also tried to wrap the \"boxSession.refresh()\" call inside a thread and use it but still getting the same error.\r\n\r\nAlso, i have a custom refresh provider, which is being triggered automatically when i call \"boxSession.refresh()\", inside the refresh provider, i have logic to hit API to get my latest token from the API and override local one and also, update expiry time inside that.\r\n\r\nThanks!!\r\n"},"comment":{"url":"https://api.github.com/repos/box/box-android-sdk/issues/comments/367198619","html_url":"https://github.com/box/box-android-sdk/issues/344#issuecomment-367198619","issue_url":"https://api.github.com/repos/box/box-android-sdk/issues/344","id":367198619,"user":{"login":"doncung","id":624482,"avatar_url":"https://avatars2.githubusercontent.com/u/624482?v=4","gravatar_id":"","url":"https://api.github.com/users/doncung","html_url":"https://github.com/doncung","followers_url":"https://api.github.com/users/doncung/followers","following_url":"https://api.github.com/users/doncung/following{/other_user}","gists_url":"https://api.github.com/users/doncung/gists{/gist_id}","starred_url":"https://api.github.com/users/doncung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doncung/subscriptions","organizations_url":"https://api.github.com/users/doncung/orgs","repos_url":"https://api.github.com/users/doncung/repos","events_url":"https://api.github.com/users/doncung/events{/privacy}","received_events_url":"https://api.github.com/users/doncung/received_events","type":"User","site_admin":false},"created_at":"2018-02-21T03:01:42Z","updated_at":"2018-02-21T03:01:42Z","author_association":"CONTRIBUTOR","body":"By main thread you are referring to UI thread? If so that is not recommended since the refresh is making an api call and can potentially take a while causing an ANR. \r\nHere is an example of the logic I'm testing with that seems to work:\r\n```\r\n   private static final BoxAuthentication.AuthenticationRefreshProvider refreshProvider = new BoxAuthentication.AuthenticationRefreshProvider() {\r\n        @Override\r\n        public BoxAuthentication.BoxAuthenticationInfo refreshAuthenticationInfo(BoxAuthentication.BoxAuthenticationInfo info) throws BoxException {\r\n            BoxAuthentication.BoxAuthenticationInfo authenticationInfo = new BoxAuthentication.BoxAuthenticationInfo(info.toJsonObject());\r\n            authenticationInfo.setAccessToken(\"latest access token from server\");\r\n            return authenticationInfo;\r\n        }\r\n\r\n        @Override\r\n        public boolean launchAuthUi(String userId, BoxSession session) {\r\n            return false;\r\n        }\r\n    };\r\n\r\nprivate void initSession(){\r\n\r\n    private void initSession() {\r\n        BoxAuthentication.getInstance().setRefreshProvider(refreshProvider);\r\n        mSession = new BoxSession(this);\r\n        mSession.setSessionAuthListener(this);\r\n        mSession.authenticate(this);\r\n        try {\r\n            mSession.refresh().get();\r\n        } catch (Exception e){\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n}\r\n\r\n\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        new Thread(){\r\n            @Override\r\n            public void run() {\r\n                initSession();\r\n            }\r\n        }.start();\r\n    }\r\n\r\n\r\n    @Override\r\n    public void onAuthCreated(BoxAuthentication.BoxAuthenticationInfo info) {\r\n        //Init file, and folder apis; and use them to fetch the root folder\r\n        mFolderApi = new BoxApiFolder(mSession);\r\n        mFileApi = new BoxApiFile(mSession);\r\n        loadRootFolder();\r\n    }\r\n\r\n    @Override\r\n    public void onAuthFailure(BoxAuthentication.BoxAuthenticationInfo info, Exception ex) {\r\n        if (ex != null) {\r\n            clearAdapter();\r\n        } else if (info == null && mOldSession != null) {\r\n            mSession = mOldSession;\r\n            mSession.setSessionAuthListener(this);\r\n            mOldSession = null;\r\n            onAuthCreated(mSession.getAuthInfo());\r\n        }\r\n    }\r\n\r\n    @Override\r\n    public void onLoggedOut(BoxAuthentication.BoxAuthenticationInfo info, Exception ex) {\r\n        clearAdapter();\r\n        initSession();\r\n    }\r\n\r\n\r\n```\r\n         \r\nBasically I'm relying on the onAuthCreated logic to know when I have a valid info object which means I should have a good access token. At which point I should be able to make the call. The initSession logic is thrown inside a thread just to make sure it is not being run on the UI thread.\r\n\r\n"}}
{"actor":{"display_login":"doncung"}}