Skip to content

Commit

Permalink
CB-5623 fix npe (#3030)
Browse files Browse the repository at this point in the history
  • Loading branch information
yagudin10 authored Oct 29, 2024
1 parent 2c7df05 commit d3be30f
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static Path getPathFromNode(@NotNull WebSession webSession, @NotNull Stri
public static DBNPathBase getNodeByPath(@NotNull WebSession webSession, @NotNull String nodePath) throws DBException {
DBRProgressMonitor monitor = webSession.getProgressMonitor();

DBNModel navigatorModel = webSession.getNavigatorModel();
DBNModel navigatorModel = webSession.getNavigatorModelOrThrow();
DBNNode node = navigatorModel.getNodeByPath(monitor, nodePath);
if (!(node instanceof DBNPathBase dbnPath)) {
throw new DBWebException("Node '" + nodePath + "' is not found in File Systems");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,18 @@ public void setLocale(@Nullable String locale) {
this.locale = locale != null ? locale : Locale.getDefault().getLanguage();
}

@Nullable
public DBNModel getNavigatorModel() {
return navigatorModel;
}

@NotNull
public DBNModel getNavigatorModelOrThrow() throws DBWebException {
if (navigatorModel != null) {
return navigatorModel;
}
throw new DBWebException("Navigator model is not found in session");
}
/**
* Returns and clears progress messages
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ public static String getConnectionContainerInfo(DBPDataSourceContainer container
return container.getName() + " [" + container.getId() + "]";
}

public static void updateConfigAndRefreshDatabases(WebSession session, String projectId) {
DBNProject projectNode = session.getNavigatorModel().getRoot().getProjectNode(session.getProjectById(projectId));
public static void updateConfigAndRefreshDatabases(WebSession session, String projectId) throws DBWebException {
DBNProject projectNode = session.getNavigatorModelOrThrow().getRoot().getProjectNode(session.getProjectById(projectId));
DBNModel.updateConfigAndRefreshDatabases(projectNode.getDatabases());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.cloudbeaver.model.session.WebSession;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.websocket.event.datasource.WSDatasourceFolderEvent;
import org.jkiss.utils.CommonUtils;

Expand All @@ -32,15 +33,19 @@ public class WSFolderUpdatedEventHandlerImpl extends WSAbstractProjectEventHandl

@Override
protected void updateSessionData(@NotNull BaseWebSession activeUserSession, @NotNull WSDatasourceFolderEvent event) {
if (activeUserSession instanceof WebSession) {
var webSession = (WebSession) activeUserSession;
if (activeUserSession instanceof WebSession webSession) {
var project = webSession.getProjectById(event.getProjectId());
if (project == null) {
log.debug("Project " + event.getProjectId() + " is not found in session " + webSession.getSessionId());
return;
}
project.getDataSourceRegistry().refreshConfig();
webSession.getNavigatorModel().getRoot().getProjectNode(project).getDatabases().refreshChildren();
DBNModel navigatorModel = webSession.getNavigatorModel();
if (navigatorModel == null) {
log.debug("Navigator model is not found in session " + webSession.getSessionId());
return;
}
navigatorModel.getRoot().getProjectNode(project).getDatabases().refreshChildren();
}
activeUserSession.addSessionEvent(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public WebConnectionInfo copyConnectionFromNode(
@NotNull WebConnectionConfig config
) throws DBWebException {
try {
DBNModel navigatorModel = webSession.getNavigatorModel();
DBNModel navigatorModel = webSession.getNavigatorModelOrThrow();
WebSessionProjectImpl project = getProjectById(webSession, projectId);
DBPDataSourceRegistry dataSourceRegistry = project.getDataSourceRegistry();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public List<WebNavigatorNodeInfo> getNavigatorNodeChildren(

DBNNode[] nodeChildren;
boolean isRootPath = CommonUtils.isEmpty(parentPath) || "/".equals(parentPath) || ROOT_DATABASES.equals(parentPath);
DBNModel navigatorModel = session.getNavigatorModel();
DBNModel navigatorModel = session.getNavigatorModelOrThrow();
Set<String> applicableDrivers = WebServiceUtils.getApplicableDriversIds();
if (isRootPath) {
DBNRoot rootNode = navigatorModel.getRoot();
Expand Down Expand Up @@ -155,8 +155,7 @@ public List<WebNavigatorNodeInfo> getNavigatorNodeParents(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();

DBNModel navigatorModel = session.getNavigatorModel();
DBNNode node = navigatorModel.getNodeByPath(monitor, nodePath);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Node '" + nodePath + "' not found");
}
Expand Down Expand Up @@ -198,7 +197,7 @@ public WebNavigatorNodeInfo getNavigatorNodeInfo(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();

DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, nodePath);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Navigator node '" + nodePath + "' not found");
}
Expand All @@ -217,7 +216,7 @@ public boolean setNavigatorNodeFilter(
try {
DBRProgressMonitor monitor = webSession.getProgressMonitor();

DBNNode node = webSession.getNavigatorModel().getNodeByPath(monitor, nodePath);
DBNNode node = webSession.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Navigator node '" + nodePath + "' not found");
}
Expand Down Expand Up @@ -256,7 +255,7 @@ public boolean refreshNavigatorNode(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();

DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, nodePath);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Navigator node '" + nodePath + "' not found");
}
Expand Down Expand Up @@ -380,10 +379,9 @@ protected List<? extends DBSObject> getCatalogs(DBRProgressMonitor monitor, DBSO
}

@Nullable
protected WebNavigatorNodeInfo getNodeFromObject(WebSession session, DBSObject object){
DBNModel navigatorModel = session.getNavigatorModel();
protected WebNavigatorNodeInfo getNodeFromObject(WebSession session, DBSObject object) throws DBWebException {
DBRProgressMonitor monitor = session.getProgressMonitor();
DBNNode node = navigatorModel.getNodeByObject(monitor, object, false);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByObject(monitor, object, false);

return node == null ? null : new WebNavigatorNodeInfo(session, node);
}
Expand All @@ -397,7 +395,7 @@ public String renameNode(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();

DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, nodePath);
DBNNode node = session.getNavigatorModelOrThrow().getNodeByPath(monitor, nodePath);
if (node == null) {
throw new DBWebException("Navigator node '" + nodePath + "' not found");
}
Expand Down Expand Up @@ -502,8 +500,9 @@ public int deleteNodes(
String projectId = null;
boolean containsFolderNodes = false;
Map<DBNNode, DBEObjectMaker> nodes = new LinkedHashMap<>();
DBNModel model = session.getNavigatorModelOrThrow();
for (String path : nodePaths) {
DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, path);
DBNNode node = model.getNodeByPath(monitor, path);
if (node == null) {
throw new DBWebException("Navigator node '" + path + "' not found");
}
Expand Down Expand Up @@ -598,9 +597,10 @@ public boolean moveNodesToFolder(
try {
DBRProgressMonitor monitor = session.getProgressMonitor();
DBNNode folderNode;
folderNode = session.getNavigatorModel().getNodeByPath(monitor, folderNodePath);
DBNModel navigatorModel = session.getNavigatorModelOrThrow();
folderNode = navigatorModel.getNodeByPath(monitor, folderNodePath);
for (String path : nodePaths) {
DBNNode node = session.getNavigatorModel().getNodeByPath(monitor, path);
DBNNode node = navigatorModel.getNodeByPath(monitor, path);
if (node == null) {
throw new DBWebException("Navigator node '" + path + "' not found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ private void checkDataEditAllowed(DBSEntity dataContainer) throws DBWebException

@NotNull
public <T> T getDataContainerByNodePath(DBRProgressMonitor monitor, @NotNull String containerPath, Class<T> type) throws DBException {
DBNNode node = webSession.getNavigatorModel().getNodeByPath(monitor, containerPath);
DBNNode node = webSession.getNavigatorModelOrThrow().getNodeByPath(monitor, containerPath);
if (node == null) {
throw new DBWebException("Container node '" + containerPath + "' not found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.jkiss.dbeaver.model.exec.trace.DBCTraceDynamic;
import org.jkiss.dbeaver.model.exec.trace.DBCTraceProperty;
import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect;
import org.jkiss.dbeaver.model.navigator.DBNModel;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.*;
Expand Down Expand Up @@ -241,8 +242,9 @@ public String generateEntityQuery(@NotNull WebSession session, @NotNull String g
private List<DBSObject> getObjectListFromNodeIds(@NotNull WebSession session, @NotNull List<String> nodePathList) throws DBWebException {
try {
List<DBSObject> objectList = new ArrayList<>(nodePathList.size());
DBNModel navigatorModel = session.getNavigatorModelOrThrow();
for (String nodePath : nodePathList) {
DBNNode node = session.getNavigatorModel().getNodeByPath(session.getProgressMonitor(), nodePath);
DBNNode node = navigatorModel.getNodeByPath(session.getProgressMonitor(), nodePath);
if (node == null) {
throw new DBException("Node '" + nodePath + "' not found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public FSFileSystem[] getAvailableFileSystems(@NotNull WebSession webSession, @N
if (project == null) {
throw new DBException(MessageFormat.format("Project ''{0}'' is not found in session", projectId));
}
DBNProject projectNode = webSession.getNavigatorModel().getRoot().getProjectNode(project);
DBNProject projectNode = webSession.getNavigatorModelOrThrow().getRoot().getProjectNode(project);
if (projectNode == null) {
throw new DBException(MessageFormat.format("Project ''{0}'' is not found in navigator model", projectId));
}
Expand All @@ -78,7 +78,7 @@ public FSFileSystem getFileSystem(
@NotNull String nodePath
) throws DBWebException {
try {
var node = webSession.getNavigatorModel().getNodeByPath(webSession.getProgressMonitor(), nodePath);
var node = webSession.getNavigatorModelOrThrow().getNodeByPath(webSession.getProgressMonitor(), nodePath);
if (!(node instanceof DBNFileSystem fs)) {
throw new DBException(MessageFormat.format("Node ''{0}'' is not File System", nodePath));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public void bindWiring(DBWBindingContext model) throws DBWebException {
private DBNNode getNodeFromPath(DataFetchingEnvironment env) throws DBException {
WebSession webSession = getWebSession(env);
String nodePath = env.getArgument("nodeId");
return webSession.getNavigatorModel().getNodeByPath(webSession.getProgressMonitor(), nodePath);
if (nodePath == null) {
throw new DBException("Node path is null");
}
return webSession.getNavigatorModelOrThrow().getNodeByPath(webSession.getProgressMonitor(), nodePath);
}
}

0 comments on commit d3be30f

Please sign in to comment.