From 33d78cc8927c6cb49632c6b11051f050d5c04e4e Mon Sep 17 00:00:00 2001 From: Achal Talati Date: Wed, 29 Oct 2025 13:30:07 +0530 Subject: [PATCH] Fixed URI issue while reading project context mapping for notebooks --- .../java/notebook/NotebookSessionManager.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookSessionManager.java b/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookSessionManager.java index f4842a0a..e8fbd7c9 100644 --- a/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookSessionManager.java +++ b/nbcode/notebooks/src/org/netbeans/modules/nbcode/java/notebook/NotebookSessionManager.java @@ -15,8 +15,10 @@ */ package org.netbeans.modules.nbcode.java.notebook; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.net.URI; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; @@ -252,11 +254,19 @@ public void closeSession(String notebookUri) { private CompletableFuture getProjectContextForNotebook(String notebookUri) { JsonObject mapping = NotebookConfigs.getInstance().getNotebookProjectMapping(); - String notebookPath = URI.create(notebookUri).getPath(); - String projectKey = mapping.has(notebookPath) - ? Paths.get(mapping.get(notebookPath).getAsString()).toUri().toString() - : notebookUri; + URI uri = URI.create(notebookUri); + String path = Path.of(uri).toAbsolutePath().toString(); + JsonElement el = mapping.get(path); + + String value = null; + if (el != null && el.isJsonPrimitive() && el.getAsJsonPrimitive().isString()) { + value = Paths.get(el.getAsString()).toUri().toString(); + } + + String projectKey = value != null ? value : notebookUri; + + LOG.log(Level.FINE, "projectKey: {0}", projectKey); Project prj = ProjectContext.getProject(projectKey); if (prj == null) {