I'm trying to trap a user into typing a correct file name unless he presses cancel or X. But if he does cancel the input my program throws a NullPointerException.
public void openSaveAsDirectory() {
    JDialog dialog = new JDialog();
    dialog.setTitle("Save file as");
    String name = JOptionPane.showInputDialog(adTable, "Please type a name for your file");
    if(name != null && !name.isEmpty()) {
        File fileName = new File(SAVE_LOCATION + FILE_SEPERATOR + name + FILE_SUFFIX);
        book.saveUser(fileName);
    }
    while(name.isEmpty()) {
            name = JOptionPane.showInputDialog(adTable, "Please type a name for your file");
    }
}
 
    