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