Skip to content

ByteData get* functions don't throw on invalid access when compiled into an exeΒ #57091

@dan-m-moore

Description

@dan-m-moore
Dart Info
- Dart 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "macos_arm64"
- on macos / Version 14.5 (Build 23F79)
- locale is en-US

I'm writing a Flutter app and noticed a difference in dart SDK behavior between Debug and Release builds, so I investigated with a pure dart example:

import 'dart:typed_data';

void main(List<String> arguments) {
  try {
    List<int> output = [];
    ByteData bytes = Uint8List.fromList(output).buffer.asByteData();
    final _ = bytes.getInt64(0);
    print('caught nothing!');
  } catch (e) {
    print('caught $e!');
  }
}

If I use dart run, this correctly throws an IndexError:

caught RangeError (byteOffset): Index out of range: index should be less than -7: 0!

If I first compile it as an exe dart compile exe bin/test_app.dart -o test_app, then the app happily runs without throwing anything:

caught nothing!

Is this an intentional optimization in the SDK? If so, what's the mechanism that determines whether or not throws are discarded during compilation? I've noticed that other throws within the class survive the compilation, but not the ones for these accessors.

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.triage-automationSee https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions