{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4492","repository_url":"https://api.github.com/repos/ReactiveX/RxJava","labels_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4492/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4492/comments","events_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4492/events","html_url":"https://github.com/ReactiveX/RxJava/issues/4492","id":175464667,"number":4492,"title":"2.x: emitting nulls from Observable.create()","user":{"login":"marcin-kozinski","id":2088582,"avatar_url":"https://avatars.githubusercontent.com/u/2088582?v=3","gravatar_id":"","url":"https://api.github.com/users/marcin-kozinski","html_url":"https://github.com/marcin-kozinski","followers_url":"https://api.github.com/users/marcin-kozinski/followers","following_url":"https://api.github.com/users/marcin-kozinski/following{/other_user}","gists_url":"https://api.github.com/users/marcin-kozinski/gists{/gist_id}","starred_url":"https://api.github.com/users/marcin-kozinski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcin-kozinski/subscriptions","organizations_url":"https://api.github.com/users/marcin-kozinski/orgs","repos_url":"https://api.github.com/users/marcin-kozinski/repos","events_url":"https://api.github.com/users/marcin-kozinski/events{/privacy}","received_events_url":"https://api.github.com/users/marcin-kozinski/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ReactiveX/RxJava/labels/Question","name":"Question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-09-07T10:12:46Z","updated_at":"2016-09-07T17:11:19Z","closed_at":null,"body":"It is not possible right now to create an observable that emits `null`s using `Observable.create()`. `Emitter`'s javadoc states `@param value the value to signal, not null` and in fact when I tried calling `emitter.onNext(null)` it is checked at runtime and results in a `NullPointerException`.\r\n\r\nCan I get any insight as to why this decision has been taken? And why only in this place, as I believe it is still possible to emit `null` via for example `Observable.just()`?\r\n\r\nIt is a fairly common pattern when you want an observable that emits multiple \"events\" that don't carry any data. Usually then you create an `Observable<Void>` and emit `null`s in `onNext()`. For example this is what I tried to write to get an observable of clicks on a view in Android (while @JakeWharton 's RxBinding doesn't have a 2.x release):\r\n\r\n``` java\r\npublic static Observable<Void> clicks(final View view) {\r\n\treturn Observable.create(emitter -> {\r\n\t\tMainThreadDisposable.verifyMainThread();\r\n\t\t\r\n\t\tview.setOnClickListener(ignored -> emitter.onNext(null)); // causes NullPointerException at runtime\r\n\t\t\r\n\t\temitter.setDisposable(new MainThreadDisposable() {\r\n\t\t\t@Override\r\n\t\t\tprotected void onDispose() {\r\n\t\t\t\tview.setOnClickListener(null);\r\n\t\t\t}\r\n\t\t});\r\n\t});\r\n}\r\n```\r\n\r\nShould I use a different way of creating such observable? Or is there a different pattern altogether for this use case in 2.x?"},"comment":{"url":"https://api.github.com/repos/ReactiveX/RxJava/issues/comments/245351278","html_url":"https://github.com/ReactiveX/RxJava/issues/4492#issuecomment-245351278","issue_url":"https://api.github.com/repos/ReactiveX/RxJava/issues/4492","id":245351278,"user":{"login":"abersnaze","id":406038,"avatar_url":"https://avatars.githubusercontent.com/u/406038?v=3","gravatar_id":"","url":"https://api.github.com/users/abersnaze","html_url":"https://github.com/abersnaze","followers_url":"https://api.github.com/users/abersnaze/followers","following_url":"https://api.github.com/users/abersnaze/following{/other_user}","gists_url":"https://api.github.com/users/abersnaze/gists{/gist_id}","starred_url":"https://api.github.com/users/abersnaze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abersnaze/subscriptions","organizations_url":"https://api.github.com/users/abersnaze/orgs","repos_url":"https://api.github.com/users/abersnaze/repos","events_url":"https://api.github.com/users/abersnaze/events{/privacy}","received_events_url":"https://api.github.com/users/abersnaze/received_events","type":"User","site_admin":false},"created_at":"2016-09-07T17:11:19Z","updated_at":"2016-09-07T17:11:19Z","body":"@akarnokd I don't think the `Ignore` class was intended to be new reactive type.  I think it was intended to be non null replacement for the `Void` type so code that uses `Observable<Void>` could be changed to `Observable<Ignore>` when using 2.x."}}
{"actor":{"display_login":"abersnaze"}}