dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.21k stars 1.57k forks source link

Null check operator used on a null value in _HttpOutgoing from http_impl #44578

Open bsutton opened 3 years ago

bsutton commented 3 years ago

I'm getting the following stack trace :

unhandled exception:
Null check operator used on a null value
#0      _HttpOutgoing._addChunk (dart:_http/http_impl.dart:1724:31)
#1      _HttpOutgoing.addStream.onData (dart:_http/http_impl.dart:1540:7)
#2      _RootZone.runUnaryGuarded (dart:async/zone.dart:1384:10)
#3      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
#4      _IterablePendingEvents.handleNext (dart:async/stream_impl.dart:559:18)
#5      _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:687:7)
#6      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#7      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#8      _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13)
#9      _Timer._runTimers (dart:isolate-patch/timer_impl.dart:404:11)
#10     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
#11     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
#12     _waitForEvent (dart:cli-patch/cli_patch.dart:8:64)
#13     _WaitForUtils.waitForEvent (dart:cli/wait_for.dart:64:12)
#14     waitFor (dart:cli/wait_for.dart:141:19)
#15     waitForEx (package:dcli/src/util/wait_for_ex.dart:20:13)
#16     SimpleGitHub.attachAssetFromFile (package:pub_release/src/git_hub_release.dart:82:5)
#17     addAsset (package:pub_release/src/create_release.dart:123:7)
#18     addExecutableAsset (package:pub_release/src/create_release.dart:110:3)
#19     addExecutablesAsAssets (package:pub_release/src/create_release.dart:89:5)
#20     _createRelease (package:pub_release/src/create_release.dart:80:3)
#21     createRelease (package:pub_release/src/create_release.dart:37:3)
#22     main (file:///home/bsutton/git/pub_release/bin/github_release.dart:53:3)

I've tried with dart 2.10.4 and dart and 2.12.0-133.2.beta

From the error I assume this is a bug related to the nnbd implementation in the http_impl package.

Running pub upgrade I see:

Resolving dependencies... (3.8s)
  _fe_analyzer_shared 14.0.0
  analyzer 0.41.1
  archive 2.0.13
  args 1.6.0
  asn1lib 0.6.5 (0.8.1 available)
  async 2.4.2
  basic_utils 2.6.3
  boolean_selector 2.0.0
  charcode 1.1.3
  cli_util 0.2.0
  collection 1.14.13
  convert 2.1.1
  coverage 0.14.2
  cron 0.2.4
  crypto 2.1.5
  csv 4.1.0
  dcli 0.39.4
  equatable 1.2.5
  ffi 0.1.3
  file 5.2.1
  file_utils 0.1.4
  github 7.0.4
  glob 1.2.0
  globbing 0.3.1
  http 0.12.2
  http_multi_server 2.2.0
  http_parser 3.1.4
  ini 2.0.1
  instant 0.3.3+1
  intl 0.16.1
  io 0.3.4
  isolate 2.0.3
  js 0.6.2
  json_annotation 3.0.1 (3.1.1 available)
  logger 0.9.4
  logging 0.11.4
  mailer 3.2.1
  matcher 0.12.9
  meta 1.2.4
  mime 0.9.7
  nginx_le_shared 4.0.13
  node_interop 1.2.1
  node_io 1.2.0
  node_preamble 1.4.12
  package_config 1.9.3
  path 1.7.0
  pedantic 1.9.2
  petitparser 3.1.0
  pointycastle 1.0.2 (2.0.0 available)
  pool 1.4.0
  pub_release 2.1.20
  pub_semver 1.4.4
  public_suffix 1.2.1 (2.0.1 available)
  pubspec 0.1.5
  punycode 0.1.0
  quiver 2.1.5
  random_string 2.1.0
  settings_yaml 2.1.5
  shelf 0.7.9
  shelf_packages_handler 2.0.0
  shelf_static 0.2.9+1
  shelf_web_socket 0.2.3
  source_map_stack_trace 2.0.0
  source_maps 0.10.9
  source_span 1.7.0
  stack_trace 1.9.6
  stream_channel 2.0.0
  string_scanner 1.0.5
  system_info 0.1.3
  term_glyph 1.1.0
  test 1.15.7
  test_api 0.2.18+1
  test_core 0.3.11+4
  typed_data 1.2.0
  uri 0.11.3+1
  utf 0.9.0+5
  uuid 2.2.2
  validators 2.0.1
  vin_decoder 0.1.3
  vm_service 4.2.0 (5.5.0 available)
  watcher 0.9.7+15
  web_socket_channel 1.1.0
  webkit_inspection_protocol 0.7.4
  xml 4.5.1
  yaml 2.2.1
No dependencies changed.
5 packages have newer versions incompatible with dependency constraints.
Try `pub outdated` for more information.

I'm a little confused by the error as it looks like the http package hasn't been converted to nnbd and it looks like none of the libraries are using nnbd.

bsutton commented 3 years ago

I've done some more digging. It does look to be a bug in http_impl.dart

on line 1736:

 if (chunk.length > _buffer!.length - _length) {

The variable _buffer is null and you can see in the _addChunk method there is no test for a non-null _buffer.

I should note that this error is preceded by a number of other exceptions in the http lib but I"m uncertain if they are related.

For the record the errors are related to:

http_headers.dart:

 void _build(BytesBuilder builder) {
    _headers.forEach((String name, List<String> values) {
      String originalName = _originalHeaderName(name);
      bool fold = _foldHeader(name);
      var nameData = originalName.codeUnits;
      builder.add(nameData);
      builder.addByte(_CharCode.COLON);
      builder.addByte(_CharCode.SP);
      for (int i = 0; i < values.length; i++) {
        if (i > 0) {
          if (fold) {
            builder.addByte(_CharCode.COMMA);
            builder.addByte(_CharCode.SP);
          } else {
            builder.addByte(_CharCode.CR);
            builder.addByte(_CharCode.LF);
            builder.add(nameData);
            builder.addByte(_CharCode.COLON);
            builder.addByte(_CharCode.SP);
          }
        }
        builder.add(values[i].codeUnits);    # cause error as values[0] is null
      }
      builder.addByte(_CharCode.CR);
      builder.addByte(_CharCode.LF);
    });
  }

line 527 results in:

Exception has occurred.
NoSuchMethodError (NoSuchMethodError: The getter 'codeUnits' was called on null.
Receiver: null
Tried calling: codeUnits)
bsutton commented 3 years ago

I had to reverting to dart 2.8.4 to get around this problem.

bsutton commented 3 years ago

After some additional testing I found a bug in my code that set the mimeType to null, which then resulted in the above error.

The above is still a bug as we shouldn't be seeing nnbd errors just because the mimeType wasn't set. Feels like the code doesn't deal with some error paths.