Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack Overflow in a program #56134

Closed
majornuts opened this issue Jul 4, 2024 · 5 comments
Closed

Stack Overflow in a program #56134

majornuts opened this issue Jul 4, 2024 · 5 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@majornuts
Copy link

Steps to reproduce

run main -> watch log for prints.

Expected results

A sorted list of times.

Actual results

Unhandled exception:
Stack Overflow
#0 DateTime._equivalentSeconds (dart:core-patch/date_patch.dart:403:3)
#1 DateTime._timeZoneOffsetInSeconds (dart:core-patch/date_patch.dart:421:29)
#2 DateTime._toLocalTimeOffset (dart:core-patch/date_patch.dart:479:18)
#3 DateTime._brokenDownDateToValue (dart:core-patch/date_patch.dart:330:33)
#4 DateTime.parse (dart:core/date_time.dart:351:20)
#5 new Dto (package:duty_planer/orders/AvailabilityOrdreSystem.dart:77:20)
#6 new Dto (package:duty_planer/orders/AvailabilityOrdreSystem.dart:74:15)
#7 new Dto (package:duty_planer/orders/AvailabilityOrdreSystem.dart:74:15)

Code sample

Code sample
void main() {
  int lalal =
      DateTime.parse("1985-07-20 20:18:04.111111").microsecondsSinceEpoch;
  print(lalal);

  Dto().currentOrderList().forEach((element) {
    print(element);
  });

  print("object2");

  Dto().currentOrderList().sort((a, b) => a.compareTo(b));

  Dto().currentOrderList().forEach((element) {
    print(element);
  });
}

class Dto implements Comparable<Dto> {
  double orderID = 1;
  int orderDate = 1;
  String name = '';
  String address = '';
  String postalCode = '';
  String city = '';
  String phone = '';
  String email = '';
  String currierID = '';
  String currierName = '';
  String currierPhone = '';

  Dto({
    this.orderID = 1,
    this.orderDate = 1,
    this.name = '',
    this.address = '',
    this.postalCode = '',
    this.city = '',
    this.phone = '',
    this.email = '',
    this.currierID = '',
    this.currierName = '',
    this.currierPhone = '',
  });

  @override
  int compareTo(other) {
    if (orderDate < (other.orderDate)) {
      return -1;
    }


    if (orderDate > other.orderDate) {
      return 1;
    }
    // age == other.age
    return 0;
  }

  List<Dto> currentOrderList() {
    return List<Dto>.from([
      ordre,
      ordre2,
      ordre3,
      ordre4,
      ordre5,
      ordre6,
      ordre7,
      ordre8,
    ]);
  }

  Dto ordre = Dto(
      orderID: 1,
      orderDate:
          DateTime.parse("2012-02-27 13:27:00").microsecondsSinceEpoch.toInt(),
      name: "bob",
      address: "1234",
      postalCode: "1234",
      city: "city",
      phone: "1234",
      email: " email",
      currierID: "1234",
      currierName: "name",
      currierPhone: "1234");

  Dto ordre2 = Dto(
      orderID: 2,
      orderDate:
          DateTime.parse("1985-07-20 20:18:04").microsecondsSinceEpoch.toInt(),
      name: "bob2",
      address: "1234",
      postalCode: "1234",
      city: "city",
      phone: "1234",
      email: " email",
      currierID: "1234",
      currierName: "name",
      currierPhone: "1234");

  Dto ordre3 = Dto(
      orderID: 2,
      orderDate:
          DateTime.parse("1986-07-20 20:18:04").microsecondsSinceEpoch.toInt(),
      name: "bob3",
      address: "1234",
      postalCode: "1234",
      city: "city",
      phone: "1234",
      email: " email",
      currierID: "1234",
      currierName: "name",
      currierPhone: "1234");

  Dto ordre4 = Dto(
      orderID: 2,
      orderDate:
          DateTime.parse("1987-07-20 20:18:04").microsecondsSinceEpoch.toInt(),
      name: "bob4",
      address: "1234",
      postalCode: "1234",
      city: "city",
      phone: "1234",
      email: " email",
      currierID: "1234",
      currierName: "name",
      currierPhone: "1234");

  Dto ordre5 = Dto(
      orderID: 2,
      orderDate:
          DateTime.parse("1988-07-20 20:18:04").microsecondsSinceEpoch.toInt(),
      name: "bob5",
      address: "1234",
      postalCode: "1234",
      city: "city",
      phone: "1234",
      email: " email",
      currierID: "1234",
      currierName: "name",
      currierPhone: "1234");

  Dto ordre6 = Dto(
      orderID: 2,
      orderDate:
          DateTime.parse("1989-07-20 20:18:04").microsecondsSinceEpoch.toInt(),
      name: "bob6",
      address: "1234",
      postalCode: "1234",
      city: "city",
      phone: "1234",
      email: " email",
      currierID: "1234",
      currierName: "name",
      currierPhone: "1234");

  Dto ordre7 = Dto(
      orderID: 2,
      orderDate:
          DateTime.parse("1990-07-20 20:18:04").microsecondsSinceEpoch.toInt(),
      name: "bob7",
      address: "1234",
      postalCode: "1234",
      city: "city",
      phone: "1234",
      email: " email",
      currierID: "1234",
      currierName: "name",
      currierPhone: "1234");

  Dto ordre8 = Dto(
      orderID: 2,
      orderDate:
          DateTime.parse("1991-07-20 20:18:04").microsecondsSinceEpoch.toInt(),
      name: "bob8",
      address: "1234",
      postalCode: "1234",
      city: "city",
      phone: "1234",
      email: " email",
      currierID: "1234",
      currierName: "name",
      currierPhone: "1234");
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.22.2, on macOS 14.5 23F79 darwin-arm64, locale en-DK) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.4) [✓] Chrome - develop for the web [✓] Android Studio (version 2024.1) [✓] VS Code (version 1.87.2) [✓] Connected device (5 available) [✓] Network resources
Unhandled exception:
Stack Overflow
#0      DateTime._equivalentSeconds (dart:core-patch/date_patch.dart:403:3)
#1      DateTime._timeZoneOffsetInSeconds (dart:core-patch/date_patch.dart:421:29)
#2      DateTime._toLocalTimeOffset (dart:core-patch/date_patch.dart:479:18)
#3      DateTime._brokenDownDateToValue (dart:core-patch/date_patch.dart:330:33)
#4      DateTime.parse (dart:core/date_time.dart:351:20)
#5      new Dto (package:duty_planer/orders/AvailabilityOrdreSystem.dart:77:20)
#6      new Dto (package:duty_planer/orders/AvailabilityOrdreSystem.dart:74:15)
#7      new Dto (package:duty_planer/orders/AvailabilityOrdreSystem.dart:74:15)

@majornuts majornuts changed the title Create an issue TimeDate Fuckery Jul 4, 2024
@dart-github-bot
Copy link
Collaborator

Summary: The user is experiencing a Stack Overflow error when parsing a date string using DateTime.parse. The error occurs during the sorting of a list of objects that contain a DateTime field.

@dart-github-bot dart-github-bot added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 4, 2024
@eernstg
Copy link
Member

eernstg commented Jul 4, 2024

Your program is an infinite loop: The creation of a Dto includes the creation of another Dto, unconditionally. Here's the core of the program:

void main() => print(Dto());

class Dto {
  Dto ordre = Dto();
}

You might want to change ordre such that it is a static member rather than an instance member. This is enough to avoid the infinite loop.

@eernstg
Copy link
Member

eernstg commented Jul 4, 2024

I'll close the issue because it is all working as intended. @majornuts, feel free to create new issues if things are still not working as expected.

@eernstg eernstg closed this as completed Jul 4, 2024
@mraleph mraleph changed the title TimeDate Fuckery Stack Overflow in a program Jul 4, 2024
@mraleph
Copy link
Member

mraleph commented Jul 4, 2024

@majornuts This is not your living room - please avoid using vulgarities.

@majornuts
Copy link
Author

Thanks for the advice, and changing the title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants