0

I have a problem, practically when I select two time slots within a week and generate them through a button all ok, but then when I go to delete a day of the week and then click again on the button "generate slots", I choose my week (where I had two days but now I have only one) I get the error on line 100 of code that I place there: enter image description here

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
mike
  • 25
  • 10
  • What's your error? – sigur Dec 03 '21 at 16:46
  • @sigur null pointer exception – mike Dec 03 '21 at 17:12
  • @sigur Hi it work now, thanks, but now the problem is a exsisting item (I have 2 iten now i have delete one item). The error is: de.hybris.platform.servicelayer.exceptions.ModelSavingException: org.springframework.dao.DuplicateKeyException: query; SQL []; Duplicate entry '8796093074981-2022-05-02 22:00:00 – mike Dec 04 '21 at 11:20
  • I suggest to you to open a new question with the details to a better understanding of the problem and its cause. @mike – sigur Dec 05 '21 at 17:05

1 Answers1

2

On the shared '100' line you basically telling to JDK compiler: for each object into list create a map entry with:

  • key the value of getDay from the object
  • value the object itself

The JDK converts it to:

  • key = object.getDay()
  • value = object

In your list there are items which are null, example: [{obj1}, {obj2}, null, ...].

This causes the TimeSlot::getDay to be null.getDay() in some cases. If you need to put null as key, you could transform it from TimeSlot::getDay to o -> o != null ? o.getDay() : null.

If you do not need null as key value, you could filter them before collecting, example adding: .filter(Objects::nonNull).

Check what-is-a-nullpointerexception-and-how-do-i-fix-it for more info.

sigur
  • 662
  • 6
  • 21