@@ -138,23 +138,32 @@ abstract class Disposable implements _Disposable {
138138 }
139139
140140 /// Automatically dispose another object when this object is disposed.
141+ ///
142+ /// The parameter may not be `null` .
141143 @mustCallSuper
142144 @protected
143145 void manageDisposable (Disposable disposable) {
146+ _throwIfNull (disposable, 'disposable' );
144147 _internalDisposables.add (disposable);
145148 }
146149
147150 /// Automatically handle arbitrary disposals using a callback.
151+ ///
152+ /// The parameter may not be `null` .
148153 @mustCallSuper
149154 @protected
150155 void manageDisposer (Disposer disposer) {
156+ _throwIfNull (disposer, 'disposer' );
151157 _internalDisposables.add (new _InternalDisposable (disposer));
152158 }
153159
154160 /// Automatically cancel a stream controller when this object is disposed.
161+ ///
162+ /// The parameter may not be `null` .
155163 @mustCallSuper
156164 @protected
157165 void manageStreamController (StreamController controller) {
166+ _throwIfNull (controller, 'controller' );
158167 _internalDisposables.add (new _InternalDisposable (() {
159168 if (! controller.hasListener) {
160169 controller.stream.listen ((_) {});
@@ -164,9 +173,12 @@ abstract class Disposable implements _Disposable {
164173 }
165174
166175 /// Automatically cancel a stream subscription when this object is disposed.
176+ ///
177+ /// The parameter may not be `null` .
167178 @mustCallSuper
168179 @protected
169180 void manageStreamSubscription (StreamSubscription subscription) {
181+ _throwIfNull (subscription, 'subscription' );
170182 _internalDisposables
171183 .add (new _InternalDisposable (() => subscription.cancel ()));
172184 }
@@ -181,4 +193,10 @@ abstract class Disposable implements _Disposable {
181193 _didDispose.complete ();
182194 return null ;
183195 }
196+
197+ void _throwIfNull (dynamic subscription, String name) {
198+ if (subscription == null ) {
199+ throw new ArgumentError .notNull (name);
200+ }
201+ }
184202}
0 commit comments