<h2 dir="auto">Steps to Reproduce</h2>
<p dir="auto">Modify any ext.flutter. service extension to throw an exception<br>
For example modify the debugPaint service extension as follows:</p>
<div class="highlight highlight-source-dart notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="      registerBoolServiceExtension(
        name: 'debugPaint',
        getter: () async =&gt; debugPaintSizeEnabled,
        setter: (bool value) {
          throw Exception(&quot;Throwing an exception here shouldn't crash&quot;); // new line.
          if (debugPaintSizeEnabled == value)
            return new Future&lt;Null&gt;.value();
          debugPaintSizeEnabled = value;
          return _forceRepaint();
        }
      );
"><pre class="notranslate">      <span class="pl-en">registerBoolServiceExtension</span>(
        name<span class="pl-k">:</span> <span class="pl-s">'debugPaint'</span>,
        getter<span class="pl-k">:</span> () <span class="pl-k">async</span> <span class="pl-k">=&gt;</span> debugPaintSizeEnabled,
        setter<span class="pl-k">:</span> (<span class="pl-c1">bool</span> value) {
          <span class="pl-k">throw</span> <span class="pl-c1">Exception</span>(<span class="pl-s">"Throwing an exception here shouldn't crash"</span>); <span class="pl-c">// new line.</span>
          <span class="pl-k">if</span> (debugPaintSizeEnabled <span class="pl-k">==</span> value)
            <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-c1">Future</span>&lt;<span class="pl-c1">Null</span>&gt;.<span class="pl-en">value</span>();
          debugPaintSizeEnabled <span class="pl-k">=</span> value;
          <span class="pl-k">return</span> <span class="pl-en">_forceRepaint</span>();
        }
      );
</pre></div>
<p dir="auto">Trigger the service extension either from flutter tool or from intellij.<br>
From flutter tool, press 'p' to trigger this extension.</p>
<p dir="auto">From intellij you just get a crash in C++ code. With flutter tool you get a bit more information.<br>
Example</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="flutter (20275): service extension method received: ext.flutter.debugPaint({isolateId: isolates/113087773})
I/flutter (20275): Action &quot;Wait for outer event loop&quot; took 0:00:00.003126
I/flutter (20275): service extension method received: ext.flutter.debugPaint({enabled: true, isolateId: isolates/113087773})
I/flutter (20275): Action &quot;Wait for outer event loop&quot; took 0:00:00.000373
I/flutter (20275): ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
I/flutter (20275): The following _Exception was thrown during a service extension callback for
I/flutter (20275): &quot;ext.flutter.debugPaint&quot;:
I/flutter (20275): Exception: Throwing an exception here shouldn't crash
I/flutter (20275): 
I/flutter (20275): When the exception was thrown, this was the stack:
I/flutter (20275): #0      _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;RendererBinding.initServiceExtensions.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:flutter/src/rendering/binding.dart:63:11)
I/flutter (20275): #1      BindingBase.registerBoolServiceExtension.&lt;anonymous closure&gt; (package:flutter/src/foundation/binding.dart:283:23)
I/flutter (20275): &lt;asynchronous suspension&gt;
I/flutter (20275): #2      BindingBase.registerServiceExtension.&lt;anonymous closure&gt; (package:flutter/src/foundation/binding.dart:392:32)
I/flutter (20275): &lt;asynchronous suspension&gt;
I/flutter (20275): #3      _runExtension (dart:developer/runtime/libdeveloper.dart:85:23)
I/flutter (20275): ════════════════════════════════════════════════════════════════════════════════════════════════════
Error -32000 received from application: Server error
JSON-RPC error -32000: Server error
package:json_rpc_2/src/client.dart 110:64              Client.sendRequest
package:json_rpc_2/src/peer.dart 68:15                 Peer.sendRequest
package:flutter_tools/src/vmservice.dart 293:13        VMService._sendRequest
package:flutter_tools/src/vmservice.dart 842:12        VM.invokeRpcRaw
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 1111:15       Isolate.invokeRpcRaw
package:flutter_tools/src/vmservice.dart 1240:20       Isolate.invokeFlutterExtensionRpcRaw
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 1274:21       Isolate._flutterToggle
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 1284:72       Isolate.flutterToggleDebugPaintSizeEnabled
package:flutter_tools/src/resident_runner.dart 213:28  FlutterDevice.toggleDebugPaintSizeEnabled
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 532:20  ResidentRunner._debugToggleDebugPaintSizeEnabled
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 714:15  ResidentRunner._commonTerminalInputHandler
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 758:34  ResidentRunner.processTerminalInput
===== asynchronous gap ===========================
dart:async/zone.dart 1134:38                           _rootRunUnary
dart:async/zone.dart 1031:19                           _CustomZone.runUnary
dart:async/zone.dart 933:7                             _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11                     _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7                      _BufferingStreamSubscription._add
dart:async/broadcast_stream_controller.dart 379:20     _SyncBroadcastStreamController._sendData
dart:async/broadcast_stream_controller.dart 254:5      _BroadcastStreamController.add
dart:async/broadcast_stream_controller.dart 480:11     _AsBroadcastStreamController.add
dart:async/zone.dart 1134:38                           _rootRunUnary
dart:async/zone.dart 1031:19                           _CustomZone.runUnary
dart:async/zone.dart 933:7                             _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11                     _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7                      _BufferingStreamSubscription._add
dart:async/stream_transformers.dart 68:11              _SinkTransformerStreamSubscription._add
dart:async/stream_transformers.dart 15:11              _EventSinkWrapper.add
dart:convert/string_conversion.dart 268:11             _StringAdapterSink.add
dart:convert/string_conversion.dart 273:7              _StringAdapterSink.addSlice
dart:convert/string_conversion.dart 348:20             _Utf8ConversionSink.addSlice
dart:convert/ascii.dart 280:17                         _ErrorHandlingAsciiDecoderSink.addSlice
dart:convert/ascii.dart 266:5                          _ErrorHandlingAsciiDecoderSink.add
dart:convert/chunked_conversion.dart 86:18             _ConverterStreamEventSink.add
dart:async/stream_transformers.dart 120:24             _SinkTransformerStreamSubscription._handleData
dart:async/zone.dart 1134:38                           _rootRunUnary
dart:async/zone.dart 1031:19                           _CustomZone.runUnary
dart:async/zone.dart 933:7                             _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11                     _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7                      _BufferingStreamSubscription._add
dart:async/stream_controller.dart 763:19               _SyncStreamController._sendData
dart:async/stream_controller.dart 639:7                _StreamController._add
dart:async/stream_controller.dart 585:5                _StreamController.add
dart:io/runtime/binsocket_patch.dart 1714:41           _Socket._onData
dart:async/zone.dart 1138:13                           _rootRunUnary
dart:async/zone.dart 1031:19                           _CustomZone.runUnary
dart:async/zone.dart 933:7                             _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11                     _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7                      _BufferingStreamSubscription._add
dart:async/stream_controller.dart 763:19               _SyncStreamController._sendData
dart:async/stream_controller.dart 639:7                _StreamController._add
dart:async/stream_controller.dart 585:5                _StreamController.add
dart:io/runtime/binsocket_patch.dart 1276:33           new _RawSocket.&lt;fn&gt;
dart:io/runtime/binsocket_patch.dart 819:14            _NativeSocket.issueReadEvent.issue
dart:async/schedule_microtask.dart 41:21               _microtaskLoop
dart:async/schedule_microtask.dart 50:5                _startMicrotaskLoop
dart:isolate/runtime/libisolate_patch.dart 113:13      _runPendingImmediateCallback
dart:isolate/runtime/libisolate_patch.dart 166:5       _RawReceivePortImpl._handleMessage

Lost connection to device.
"><pre class="notranslate"><code class="notranslate">flutter (20275): service extension method received: ext.flutter.debugPaint({isolateId: isolates/113087773})
I/flutter (20275): Action "Wait for outer event loop" took 0:00:00.003126
I/flutter (20275): service extension method received: ext.flutter.debugPaint({enabled: true, isolateId: isolates/113087773})
I/flutter (20275): Action "Wait for outer event loop" took 0:00:00.000373
I/flutter (20275): ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
I/flutter (20275): The following _Exception was thrown during a service extension callback for
I/flutter (20275): "ext.flutter.debugPaint":
I/flutter (20275): Exception: Throwing an exception here shouldn't crash
I/flutter (20275): 
I/flutter (20275): When the exception was thrown, this was the stack:
I/flutter (20275): #0      _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;RendererBinding.initServiceExtensions.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (package:flutter/src/rendering/binding.dart:63:11)
I/flutter (20275): #1      BindingBase.registerBoolServiceExtension.&lt;anonymous closure&gt; (package:flutter/src/foundation/binding.dart:283:23)
I/flutter (20275): &lt;asynchronous suspension&gt;
I/flutter (20275): #2      BindingBase.registerServiceExtension.&lt;anonymous closure&gt; (package:flutter/src/foundation/binding.dart:392:32)
I/flutter (20275): &lt;asynchronous suspension&gt;
I/flutter (20275): #3      _runExtension (dart:developer/runtime/libdeveloper.dart:85:23)
I/flutter (20275): ════════════════════════════════════════════════════════════════════════════════════════════════════
Error -32000 received from application: Server error
JSON-RPC error -32000: Server error
package:json_rpc_2/src/client.dart 110:64              Client.sendRequest
package:json_rpc_2/src/peer.dart 68:15                 Peer.sendRequest
package:flutter_tools/src/vmservice.dart 293:13        VMService._sendRequest
package:flutter_tools/src/vmservice.dart 842:12        VM.invokeRpcRaw
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 1111:15       Isolate.invokeRpcRaw
package:flutter_tools/src/vmservice.dart 1240:20       Isolate.invokeFlutterExtensionRpcRaw
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 1274:21       Isolate._flutterToggle
===== asynchronous gap ===========================
package:flutter_tools/src/vmservice.dart 1284:72       Isolate.flutterToggleDebugPaintSizeEnabled
package:flutter_tools/src/resident_runner.dart 213:28  FlutterDevice.toggleDebugPaintSizeEnabled
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 532:20  ResidentRunner._debugToggleDebugPaintSizeEnabled
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 714:15  ResidentRunner._commonTerminalInputHandler
===== asynchronous gap ===========================
package:flutter_tools/src/resident_runner.dart 758:34  ResidentRunner.processTerminalInput
===== asynchronous gap ===========================
dart:async/zone.dart 1134:38                           _rootRunUnary
dart:async/zone.dart 1031:19                           _CustomZone.runUnary
dart:async/zone.dart 933:7                             _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11                     _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7                      _BufferingStreamSubscription._add
dart:async/broadcast_stream_controller.dart 379:20     _SyncBroadcastStreamController._sendData
dart:async/broadcast_stream_controller.dart 254:5      _BroadcastStreamController.add
dart:async/broadcast_stream_controller.dart 480:11     _AsBroadcastStreamController.add
dart:async/zone.dart 1134:38                           _rootRunUnary
dart:async/zone.dart 1031:19                           _CustomZone.runUnary
dart:async/zone.dart 933:7                             _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11                     _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7                      _BufferingStreamSubscription._add
dart:async/stream_transformers.dart 68:11              _SinkTransformerStreamSubscription._add
dart:async/stream_transformers.dart 15:11              _EventSinkWrapper.add
dart:convert/string_conversion.dart 268:11             _StringAdapterSink.add
dart:convert/string_conversion.dart 273:7              _StringAdapterSink.addSlice
dart:convert/string_conversion.dart 348:20             _Utf8ConversionSink.addSlice
dart:convert/ascii.dart 280:17                         _ErrorHandlingAsciiDecoderSink.addSlice
dart:convert/ascii.dart 266:5                          _ErrorHandlingAsciiDecoderSink.add
dart:convert/chunked_conversion.dart 86:18             _ConverterStreamEventSink.add
dart:async/stream_transformers.dart 120:24             _SinkTransformerStreamSubscription._handleData
dart:async/zone.dart 1134:38                           _rootRunUnary
dart:async/zone.dart 1031:19                           _CustomZone.runUnary
dart:async/zone.dart 933:7                             _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11                     _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7                      _BufferingStreamSubscription._add
dart:async/stream_controller.dart 763:19               _SyncStreamController._sendData
dart:async/stream_controller.dart 639:7                _StreamController._add
dart:async/stream_controller.dart 585:5                _StreamController.add
dart:io/runtime/binsocket_patch.dart 1714:41           _Socket._onData
dart:async/zone.dart 1138:13                           _rootRunUnary
dart:async/zone.dart 1031:19                           _CustomZone.runUnary
dart:async/zone.dart 933:7                             _CustomZone.runUnaryGuarded
dart:async/stream_impl.dart 336:11                     _BufferingStreamSubscription._sendData
dart:async/stream_impl.dart 263:7                      _BufferingStreamSubscription._add
dart:async/stream_controller.dart 763:19               _SyncStreamController._sendData
dart:async/stream_controller.dart 639:7                _StreamController._add
dart:async/stream_controller.dart 585:5                _StreamController.add
dart:io/runtime/binsocket_patch.dart 1276:33           new _RawSocket.&lt;fn&gt;
dart:io/runtime/binsocket_patch.dart 819:14            _NativeSocket.issueReadEvent.issue
dart:async/schedule_microtask.dart 41:21               _microtaskLoop
dart:async/schedule_microtask.dart 50:5                _startMicrotaskLoop
dart:isolate/runtime/libisolate_patch.dart 113:13      _runPendingImmediateCallback
dart:isolate/runtime/libisolate_patch.dart 166:5       _RawReceivePortImpl._handleMessage

Lost connection to device.

</code></pre></div>
<p dir="auto"><strong>Problem:</strong> nesting 2 or more widgets in the hierarchy that both use <code class="notranslate">PageStorage</code> without identifiers -- e.g. an <code class="notranslate">ExpansionTile</code>, and a <code class="notranslate">Scrollable</code> -- results in widgets reading/writing into/from the same location; this in turn results in an exception, since the value types used by these widgets are different: the <code class="notranslate">ExpansionTile</code> reads/writes a <code class="notranslate">boolean</code> (isExpanded), the <code class="notranslate">ScrollController</code> a <code class="notranslate">double</code> (scrollPosition). If the types were the same, the problem would be even worse, since the code would run with unexpected behavior.</p>
<p dir="auto"><strong>Cause:</strong> <code class="notranslate">PageStorage.{read,write}State()</code> has an optional parameter -- the "identifier" -- under which state info that needs to outlive a widget can be stored. If state is written/read without specifying an identifier, the <code class="notranslate">PageStorage</code> uses the <code class="notranslate">PageStorageKey</code> to compute an identifier as a fallback. This results in the same identifier being computed for widgets with a common <code class="notranslate">PageStorageKey</code> ancestor.</p>
<p dir="auto"><strong>Workaround (or intended use?!):</strong> a separate <code class="notranslate">PageStorageKey</code> for each of these widgets.</p>
<p dir="auto"><strong>Suggested fix:</strong> start using the identifier in <code class="notranslate">PageStorage.{read,write}State()</code>?<br>
Also, in the current implementation, for the state to be properly restored, we are forced to specify a <code class="notranslate">PageStorageKey</code> for these widgets. Shouldn't all this stashing of state be handled transparently inside the widgets (without the need to explicitly give them <code class="notranslate">PageStorageKeys</code>), so that we are free to specify our own keys (e.g. a <code class="notranslate">GlobalKey</code>) when needed?</p>