Throw NPE when selected server is null

This commit is contained in:
yushijinhun 2018-07-21 09:57:47 +08:00
parent b820aad358
commit d30758a2a8
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4

View File

@ -50,10 +50,10 @@ import org.jackhuang.hmcl.util.Constants;
import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.Logging;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.logging.Level; import java.util.logging.Level;
import static java.util.Objects.requireNonNull;
import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG; import static org.jackhuang.hmcl.setting.ConfigHolder.CONFIG;
import static org.jackhuang.hmcl.ui.FXUtils.jfxListCellFactory; import static org.jackhuang.hmcl.ui.FXUtils.jfxListCellFactory;
import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating; import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating;
@ -125,8 +125,7 @@ public class AddAccountPane extends StackPane {
private Object getAuthAdditionalData() { private Object getAuthAdditionalData() {
AccountFactory<?> factory = cboType.getSelectionModel().getSelectedItem(); AccountFactory<?> factory = cboType.getSelectionModel().getSelectedItem();
if (factory == Accounts.FACTORY_AUTHLIB_INJECTOR) { if (factory == Accounts.FACTORY_AUTHLIB_INJECTOR) {
// throw an exception if none is selected return requireNonNull(cboServers.getSelectionModel().getSelectedItem(), "selected server cannot be null");
return Optional.ofNullable(cboServers.getSelectionModel().getSelectedItem()).get();
} }
return null; return null;
} }