From a2b0959767bcb9c4412f7886d4b07b3fc5078bab Mon Sep 17 00:00:00 2001 From: Martin Weick Date: Thu, 24 May 2018 13:58:43 +0200 Subject: Fix NPE when choseVehicle is null --- .../controller/RegistrationWindowController.java | 39 ++++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java index ac6470e..4653663 100644 --- a/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java +++ b/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/einsatzverwaltung/controller/RegistrationWindowController.java @@ -149,25 +149,28 @@ public class RegistrationWindowController { LOG.debug("Create Button clicked"); Set registrations = new HashSet<>(); - - for (Employee employee : chosenEmployees) { - registrations.add( - Registration.builder() - .id(chosenVehicle.id()) - .employee(employee) - .start( - LocalDateTime.of( - LocalDate.now(), - LocalTime.of(cbStart.getValue(), 0)) - .toInstant(OffsetDateTime.now().getOffset())) - .end( - LocalDateTime.of( - LocalDate.now(), - LocalTime.of(cbEnd.getValue(), 0)) - .toInstant(OffsetDateTime.now().getOffset())) - .build()); - } try { + if (chosenVehicle == null) { + throw new InvalidVehicleException("no Vehicle"); + } + for (Employee employee : chosenEmployees) { + registrations.add( + Registration.builder() + .id(chosenVehicle.id()) + .employee(employee) + .start( + LocalDateTime.of( + LocalDate.now(), + LocalTime.of(cbStart.getValue(), 0)) + .toInstant(OffsetDateTime.now().getOffset())) + .end( + LocalDateTime.of( + LocalDate.now(), + LocalTime.of(cbEnd.getValue(), 0)) + .toInstant(OffsetDateTime.now().getOffset())) + .build()); + } + registrationService.add(chosenVehicle.id(), registrations); chosenEmployees.clear(); ((Stage) lVehicles.getScene().getWindow()).close(); -- cgit v1.2.3-70-g09d2