I was using ternary if like in example:
carDto.setTireId(car.getTire() == null ? null : car.getTire().getId());
It was causing NullPointer exception. I did not understand why, but then I noticed that setTireId expects integer as parameter. So when I changed to
carDto.setTireId(car.getTire() == null ? 0 : car.getTire().getId());
everything started working as expected.
When I tried
carDto.setTireId(null);
I got compilation exception as expected.
My question is: why is the first statement not failing at compile time? In this case it was simple human error, but it could make a hard-to-find bug.