Skip to content

fix(intellij): project graph or project graph nodes may be null if project is misconfigured #2584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class NxAngularConfigService(private val project: Project, private val cs: Corou
return
}
val projectFiles =
workspace.projectGraph.nodes.values
(workspace.projectGraph?.nodes ?: return)
.values
.asSequence()
// TODO: use framework metadata in the future, for now just register all projects
// .filter { project ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class NxToolWindowPanel(private val project: Project) : SimpleToolWindowPanel(tr
it.second
}
}
} else if (workspace == null || workspace.projectGraph.nodes.isEmpty()) {
} else if (workspace == null || workspace.projectGraph?.nodes.isNullOrEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression workspace.projectGraph?.nodes.isNullOrEmpty() has a potential null safety issue. When projectGraph is null, the safe call operator (?.) prevents a null pointer exception, but the nodes property is still accessed without null safety.

For proper null safety handling, this should be changed to:

workspace.projectGraph?.nodes?.isNullOrEmpty() ?: true

This ensures that when projectGraph is null, the entire expression evaluates to true (equivalent to nodes being empty), preventing potential runtime errors.

Suggested change
} else if (workspace == null || workspace.projectGraph?.nodes.isNullOrEmpty()) {
} else if (workspace == null || workspace.projectGraph?.nodes?.isNullOrEmpty() ?: true) {

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

noProjectsComponent
} else {
projectTreeComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ abstract class NxTreeBuilderBase(private val nxWorkspace: NxWorkspace?) {
if (nxWorkspace == null) {
return emptyArray()
}
return nxWorkspace.projectGraph.nodes
return (nxWorkspace.projectGraph?.nodes ?: return emptyArray())
.filter { it.value.data.targets?.contains(targetsListNode.targetName) ?: false }
.map {
NxSimpleNode.Target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.*

data class NxWorkspace(
val validWorkspaceJson: Boolean,
val projectGraph: NxProjectGraph,
val projectGraph: NxProjectGraph?,
val daemonEnabled: Boolean?,
val workspacePath: String,
val errors: Array<NxError>?,
Expand Down Expand Up @@ -53,7 +53,7 @@ data class NxWorkspace(

data class WorkspaceLayout(val appsDir: String?, val libsDir: String?)

data class NxProjectGraph(val nodes: Map<String, NxProjectGraphProjectNode>)
data class NxProjectGraph(val nodes: Map<String, NxProjectGraphProjectNode>?)

data class NxProjectGraphProjectNode(val name: String, val type: String, val data: NxProject)

Expand Down
Loading