{"action":"opened","issue":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4644","repository_url":"https://api.github.com/repos/ReactiveX/RxJava","labels_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4644/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4644/comments","events_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4644/events","html_url":"https://github.com/ReactiveX/RxJava/issues/4644","id":180186444,"number":4644,"title":"Handling null in RxJava2","user":{"login":"paveldudka","id":3103759,"avatar_url":"https://avatars.githubusercontent.com/u/3103759?v=3","gravatar_id":"","url":"https://api.github.com/users/paveldudka","html_url":"https://github.com/paveldudka","followers_url":"https://api.github.com/users/paveldudka/followers","following_url":"https://api.github.com/users/paveldudka/following{/other_user}","gists_url":"https://api.github.com/users/paveldudka/gists{/gist_id}","starred_url":"https://api.github.com/users/paveldudka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paveldudka/subscriptions","organizations_url":"https://api.github.com/users/paveldudka/orgs","repos_url":"https://api.github.com/users/paveldudka/repos","events_url":"https://api.github.com/users/paveldudka/events{/privacy}","received_events_url":"https://api.github.com/users/paveldudka/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-29T23:16:36Z","updated_at":"2016-09-29T23:16:36Z","closed_at":null,"body":"With the upcoming RxJava2 release one of the important changes is that `null` is no longer accepted as a stream element.\r\n\r\nHonestly, I have mixed feelings about this change and part of me understands that it will enforce clean APIs, but I can see a number of use cases when this might be a problem.\r\n\r\nFor instance, in my app I have an in-memory cache:\r\n\r\n    @Nullable CacheItem findCacheItem(long id);\r\n\r\nCacheItem might not be present in cache, so method might return null value.\r\n\r\nThe way it is used with Rx* - is as following:\r\n\r\n    Observable<CacheItem> getStream(final long id) {\r\n        return Observable.fromCallable(new Callable<CacheItem>() {\r\n            @Override public CacheItem call() throws Exception {\r\n                return findCacheItem(id);\r\n            }\r\n        });\r\n    }\r\n\r\nSo with this approach, I might get null in my stream which is totally valid situation, so it is handled properly on receiving side - let's say UI changes its state if item is not present in cache:\r\n\r\n    Observable.just(user)\r\n              .map(user -> user.getName())\r\n              .map(name -> convertNameToId(name))\r\n              .map(id -> findCacheItem(id))\r\n              .map(cacheItem -> getUserInfoFromCacheItem(cacheItem))\r\n              .subscribe(\r\n                  userInfo -> {\r\n                      if(userInfo != null) showUserInfo();\r\n                      else showPrompt();\r\n                  }\r\n              );\r\n\r\nWith RxJava2 I am no longer allowed to post `null` down the stream, so I either need to wrap my CacheItem into some other class and make my stream produce that wrapper instead or make quite big architectural changes.\r\n\r\nWrapping every single stream element into nullable counterpart doesn't look right to me.\r\n\r\nAm I missing something fundamental here? \r\n\r\nIt seems like the situation like mine is quite popular, so Im curious what is the recommended strategy to tackle this problem given new \"no null\" policy in RxJava2?\r\n    "}}
{"actor":{"display_login":"paveldudka"}}