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

Branch fixes delete training 2 #93

Merged

Conversation

sudogene
Copy link

IMPORTANT: Search student by Id
Given how tricky it is to maintain immutable student objects in an implicitly mutable manner (we modify a lot of stuff) and especially how the "same" student is being contained in both student list and INDIVIDUAL training, going forward, we should point to students using Id values instead of equality checks.

A True Story Example - Major bug

  1. Create two trainings, T1 and T2
  2. Add student Alex to T1 - ts-add 1 1
  3. Add student Alex to T2 - ts-add 2 1
  4. Delete training T1 - delete-training 1
    a. Loop through all students within T1 training list of students
    b. Remove T1's date time from that student's training schedule
    c. Update the Model using model.setStudent(oldStudent, newStudent)

There will be a StudentNotFoundException for 4c because:

  • Alex object in T1 has one training session: T1
  • Alex object in Model has two training sessions: T1 and T2
  • .equals() will be false ==> Student not found

T1 stores the older Alex object and will not match any other newer Alex object IF we use .equals().
Hence, the next best thing we can use is Id which was created to be unique and immutable.


The bug above has been fixed.

@sudogene sudogene requested a review from a team October 14, 2020 15:41
@yejiadong yejiadong linked an issue Oct 14, 2020 that may be closed by this pull request
@yejiadong yejiadong added this to the v1.2b milestone Oct 14, 2020
@yejiadong yejiadong added this to To do in CanoE-COACH via automation Oct 14, 2020
@yejiadong yejiadong added the type.Bug A bug label Oct 14, 2020
Copy link

@yejiadong yejiadong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

return studentsList.stream()
.filter(student -> student.getId().equals(id))
.findFirst()
.get();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if studentsList empty, is it safe that .get() will not throw a null pointer error?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's assumed here that there will always be the Id existing in the list, is there a scenario that this wont happen?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, but might be good to include an assertion here in case of code changes in future

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep thanks, shall do that. We see how this find by id goes, best is we abstract it to a util method

@yejiadong yejiadong moved this from To do to Done in CanoE-COACH Oct 14, 2020
Copy link

@yejiadong yejiadong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@yejiadong yejiadong merged commit f20f1a8 into AY2021S1-CS2103-F10-1:master Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
CanoE-COACH
  
Done
Development

Successfully merging this pull request may close these issues.

Bug in the Deletion of Entire Trainings
2 participants