Overview
When a user goes to open an existing profile, then changes his/her mind and chooses to cancel the operation without choosing a file, unhandled exceptions cause errors and unwanted behavior in RaiderPlanner.
Steps to Recreate
Open the Open Profile dialog, then click cancel:
Resulting Problems
Immediately after clicking "Cancel", a NullPointerException is thrown. The stack trace is printed to the console:
Caused by: java.lang.NullPointerException
at edu.wright.cs.raiderplanner.controller.MainController.loadFile(MainController.java:253)
at edu.wright.cs.raiderplanner.controller.MenuController.openProfile(MenuController.java:580)
... 73 more
The next time the user tries to open an existing profile (by clicking the "Open Profile" button again), he/she gets the following error:
After clicking past this error, the user is presented with the file chooser dialog again. The user can either select a new profile without further issue, or recreate the above issue by clicking "Cancel" again.
Cause of Problems
This problem stems from the way the file chooser handles passing the .dat file back to RaiderPlanner. When the file chooser is closed, it simply returns the selected file back to RaiderPlanner. If no file is selected, as is the case when the user chooses to "Cancel" a file selection, a null pointer is returned. This triggers the NullPointerException shown above. Although the exception is unhandled, RaiderPlanner manages to run past it. However, the null pointer is set to RaiderPlanner's current profile file. When the user goes to open a new profile again, the function called to open the file chooser dialog tries to save the current user's profile data. As the current profile is currently set to "null", the user gets an error saying that RaiderPlanner "Failed to save your data".
Resolution
The issue can be resolved by checking whether the file object returned from the file chooser is null. If null, RaiderPlanner should not set the current profile file to this null pointer.