crbench//

← all cases

LSP: do not compute text edits in source actions on resolve

Tier 2 medium java · cross-file · real merged PR from apache/netbeans #6990

Ground-truth defects

d1 · correctness · medium
The new source-action code generators emit commands with a hardcoded `nbls.`-prefixed name (e.g. `new Command(..., "nbls.generate.code", ...)`) instead of routing the name through `Utils.encodeCommand(command, client.getNbCodeCapabilities())` the way the sibling generators do. Any LSP client whose capabilities use a different command prefix gets a dead source-action menu. The fix runs the command name through `encodeCommand` so it respects the client's prefix.

The change under review

diff (truncated — full diff)
diff --git a/enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java b/enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java
index 93c9a6694307..bad8e1beab84 100644
--- a/enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java
+++ b/enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java
@@ -18,14 +18,21 @@
  */
 package org.netbeans.modules.micronaut.db;
 
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
 import com.sun.source.tree.ClassTree;
 import com.sun.source.tree.Tree;
 import com.sun.source.util.TreePath;
 import java.awt.Dialog;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.element.TypeElement;
@@ -33,13 +40,13 @@
 import javax.lang.model.type.DeclaredType;
 import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
+import javax.lang.model.util.ElementFilter;
 import javax.swing.JButton;
 import javax.swing.JComponent;
 import javax.swing.text.Document;
 import javax.swing.text.JTextComponent;
 import org.netbeans.api.editor.mimelookup.MimeRegistration;
 import org.netbeans.api.java.source.CompilationController;
-import org.netbeans.api.java.source.ElementHandle;
 import org.netbeans.api.java.source.GeneratorUtilities;
 import org.netbeans.api.java.source.JavaSource;
 import org.netbeans.api.java.source.ModificationResult;
@@ -47,7 +54,7 @@
 import org.netbeans.api.java.source.TreeUtilities;
 import org.netbeans.api.java.source.WorkingCopy;
 import org.netbeans.api.lsp.CodeAction;
-import org.netbeans.api.lsp.LazyCodeAction;
+import org.netbeans.api.lsp.Command;
 import org.netbeans.api.lsp.Range;
 import org.netbeans.api.lsp.TextDocumentEdit;
 import org.netbeans.api.lsp.TextEdit;
@@ -56,25 +63,39 @@
 import org.netbeans.modules.parsing.spi.ParseException;
 import org.netbeans.spi.editor.codegen.CodeGenerator;
 import org.netbeans.spi.lsp.CodeActionProvider;
+import org.netbeans.spi.lsp.CommandProvider;
 import org.openide.DialogDescriptor;
 import org.openide.DialogDisplayer;
 import org.openide.NotifyDescriptor;
 import org.openide.filesystems.FileObject;
+import org.openide.filesystems.URLMapper;
 import org.openide.util.Exceptions;
 import org.openide.util.Lookup;
 import org.openide.util.NbBundle;
+import org.openide.util.RequestProcessor;
 import org.openide.util.Union2;
+import org.openide.util.lookup.ServiceProviders;
 import org.openide.util.lookup.ServiceProvider;
 
 /**
  *
  * @author Dusan Balek
  */
-@ServiceProvider(service = CodeActionProvider.class)
-public class MicronautDataEndpointGenerator implements CodeActionProvider {
+@ServiceProviders({
+    @ServiceProvider(service = CodeActionProvider.class),
+    @ServiceProvider(service = CommandProvider.class)
+})
+public class MicronautDataEndpointGenerator implements CodeActionProvider, CommandProvider {
 
     private static final String SOURCE = "source";
     private static final String CONTROLLER_ANNOTATION_NAME = "io.micronaut.http.annotation.Controller";
+    private static final String GENERATE_DATA_ENDPOINT = "nbls.micronaut.generate.data.endpoint";
+    private static final String URI =  "uri";
+    private static final String OFFSET =  "offset";
+    private static final String REPOSITORIES =  "repositories";
+    private static final String ENDPOINTS =  "endpoints";
+
+    private final Gson gson = new Gson();
 
     @Override
     @NbBundle.Messages({
@@ -126,34 +147,12 @@ public List<CodeAction> getCodeActions(Document doc, Range range, Lookup context
                 }
             });
             if (!endpoints.isEmpty()) {
-                FileObject fo = cc.getFileObject();
-                List<ElementHandle<VariableElement>> repositoryHandles = repositories.stream().map(repository -> ElementHandle.create(repository)).collect(Collectors.toList());
-                return Collections.singletonList(new LazyCodeAction(Bundle.DN_GenerateDataEndpoint(), SOURCE, null, () -> {
-                    try {
-                        List<NotifyDescriptor.QuickPick.Item> items = endpoints.stream().map(endpoint -> new NotifyDescriptor.QuickPick.Item(endpoint, null)).collect(Collectors.toList());
-                        NotifyDescriptor.QuickPick pick = new NotifyDescriptor.QuickPick(Bundle.DN_GenerateDataEndpoint(), Bundle.DN_SelectEndpoints(), items, true);
-                        if (DialogDescriptor.OK_OPTION != DialogDisplayer.getDefault().notify(pick)) {
-                            return null;
-                        }
-                        List<String> selectedIds = new ArrayList<>();
-                        for (NotifyDescriptor.QuickPick.Item item : pick.getItems()) {
-                            if (item.isSelected()) {
-                                selectedIds.add(item.getLabel());
-                            }
-                        }
-                        if (selectedIds.isEmpty()) {
-                            return null;
-                        }
-                        JavaSource js = JavaSource.forFileObject(fo);
-                        if (js == null) {
-                            throw new IOException("Cannot get JavaSource for: " + fo.toURL().toString());
-                        }
-                        return modify2Edit(js, getTask(offset, repositoryHandles, selectedIds));
-                    } catch (IOException ex) {
-                        Exceptions.printStackTrace(ex);
-                    }
-                    return null;
-                }));
+                Map<String, Object> data = new HashMap<>();
+                data.put(URI, cc.getFileObject().toURI().toString());
+                data.put(OFFSET, offset);
+                data.put(REPOSITORIES, repositories.stream().map(repository -> repository.getSimpleName().toString()).collect(Collectors.toList()));
+                data.put(ENDPOINTS, endpoints);
+                return Collections.singletonList(new CodeAction(Bundle.DN_GenerateDataEndpoint(), SOURCE, new Command(Bundle.DN_GenerateDataEndpoint(), "nbls.generate.code", Arrays.asList(GENERATE_DATA_ENDPOINT, data)), null));
             }
         } catch (IOException | ParseException ex) {
             Exceptions.printStackTrace(ex);
@@ -161,44 +160,94 @@ public List<CodeAction> getCodeActions(Document doc, Range range, Lookup context
         return Collections.emptyList();
     }
 
-    private static Task<WorkingCopy> getTask(int offset, List<ElementHandle<VariableElement>> repositoryHandles, List<String> endpointIds) {
+    @Override
+    public Set<String> getCommands() {
+        return Collections.singleton(GENERATE_DATA_ENDPOINT);
+    }
+
+    @Override
+    public CompletableFuture<Object> runCommand(String command, List<Object> arguments) {
+        if (arguments.isEmpty()) {
+            return CompletableFuture.completedFuture(null);
+        }
+        JsonObject data = (JsonObject) arguments.get(0);
+        CompletableFuture<Object> future = new CompletableFuture<>();
+        RequestProcessor.getDefault().post(() -> {
+            try {
+                String uri = data.getAsJsonPrimitive(URI).getAsString();
+                FileObject fo = URLMapper.findFileObject(java.net.URI.create(uri).toURL());
+                JavaSource js = fo != null ? JavaSource.forFileObject(fo) : null;
+                if (js == null) {
+                    throw new IOException("Cannot get JavaSource for: " + uri);
+                }
+                int offset = data.getAsJsonPrimitive(OFFSET).getAsInt();
+                List<NotifyDescriptor.QuickPick.Item> items = Arrays.asList(gson.fromJson(data.get(ENDPOINTS), String[].class)).stream().map(endpoint -> new NotifyDescriptor.QuickPick.Item(endpoint, null)).collect(Collectors.toList());
+                NotifyDescriptor.QuickPick pick = new NotifyDescriptor.QuickPick(Bundle.DN_GenerateDataEndpoint(), Bundle.DN_SelectEndpoints(), items, true);
+                if (DialogDescriptor.OK_OPTION != DialogDisplayer.getDefault().notify(pick)) {
+                    future.complete(null);
+                } else {
+                    List<String> selectedIds = new ArrayList<>();
+                    for (NotifyDescriptor.QuickPick.Item item : pick.getItems()) {
+                        if (item.isSelected()) {
+                            selectedIds.add(item.getLabel());
+                        }
+                    }
+                    if (selectedIds.isEmpty()) {
+                        future.complete(null);
+                    } else {
+                        List<String> repositoryNames = Arrays.asList(gson.fromJson(data.get(REPOSITORIES), String[].class));
+                        future.complete(modify2Edit(js, getTask(offset, repositoryNames, selectedIds)));
+                    }
+                }
+            } catch (IOException ex) {
+                future.completeExceptionally(ex);
+            }
+        });
+        return future;
+    }
+
+    private static Task<WorkingCopy> getTask(int offset, List<String> repositoryNames, List<String> endpointIds) {
         return copy -> {
             copy.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
             TreePath tp = copy.getTreeUtilities().pathFor(offset);
             tp = copy.getTreeUtilities().getPathElementOfKind(TreeUtilities.CLASS_TREE_KINDS, tp);
             if (tp != null) {
                 ClassTree clazz = (ClassTree) tp.getLeaf();
-                List<Tree> members = new ArrayList<>();
-                for (ElementHandle<VariableElement> repositoryHandle : repositoryHandles) {
-                    VariableElement repository = repositoryHandle.resolve(copy);
-                    if (repository != null) {
-                        TypeMirror repositoryType = repository.asType();
-                        if (repositoryType.getKind() == TypeKind.DECLARED) {
-                            TypeElement repositoryTypeElement = (TypeElement) ((DeclaredType) repositoryType).asElement();
-                            String id = null;
-                            if (repositoryHandles.size() > 1) {
-                                id = '/' + repositoryTypeElement.getSimpleName().toString().toLowerCase();
-                                if (id.endsWith("repository")) {
-                                    id = id.substring(0, id.length() - 10);
-                                }
-                            }
-                            for (String endpointId : endpointIds) {
-                                String delegateMethodName = null;
-                                if (endpointId.equals(id != null ? id + "/ -- GET" : "/ -- GET")) {
-                                    delegateMethodName = "findAll";
-                                } else if (endpointId.equals(id != null ? id + "/{id} -- GET" : "/{id} -- GET")) {
-                                    delegateMethodName = "findById";
-                                } else if (endpointId.equals(id != null ? id + "/{id} -- DELETE" : "/{id} -- DELETE")) {
-                                    delegateMethodName = "deleteById";
+                TypeElement te = (TypeElement) copy.getTrees().getElement(tp);
+                if (te != null) {
+                    List<VariableElement> fields = ElementFilter.fieldsIn(te.getEnclosedElements());
+                    List<Tree> members = new ArrayList<>();
+                    for (String repositoryName : repositoryNames) {
+                        VariableElement repository = fields.stream().filter(ve -> repositoryName.contentEquals(ve.getSimpleName())).findFirst().orElse(null);
+                        if (repository != null) {
+                            TypeMirror repositoryType = repository.asType();
+                            if (repositoryType.getKind() == TypeKind.DECLARED) {
+                                TypeElement repositoryTypeElement = (TypeElement) ((DeclaredType) repositoryType).asElement();
+                                String id = null;
+                                if (repositoryNames.size() > 1) {
+                                    id = '/' + repositoryTypeElement.getSimpleName().toString().toLowerCase();
+                                    if (id.endsWith("repository")) {
+                                        id = id.substring(0, id.length() - 10);
+                                    }
                                 }
-                                if (delegateMethodName != null) {
-                                    members.add(Utils.createControllerDataEndpointMethod(copy, repositoryTypeElement, repository.getSimpleName().toString(), delegateMethodName, id));
+                                for (String endpointId : endpointIds) {
+                                    String delegateMethodName = null;
+                                    if (endpointId.equals(id != null ? id + "/ -- GET" : "/ -- GET")) {
+                                        delegateMethodName = "findAll";
+                                    } else if (endpointId.equals(id != null ? id + "/{id} -- GET" : "/{id} -- GET")) {
+                                        delegateMethodName = "findById";
+                                    } else if (endpointId.equals(id != null ? id + "/{id} -- DELETE" : "/{id} -- DELETE")) {
+                                        delegateMethodName = "deleteById";
+                                    }
+                                    if (delegateMethodName != null) {
+                                        members.add(Utils.createControllerDataEndpointMethod(copy, repositoryTypeElement, repository.getSimpleName().toString(), delegateMethodName, id));
+                                    }
                                 }
                             }
                         }
                     }
+                    copy.rewrite(clazz, GeneratorUtilities.get(copy).insertClassMembers(clazz, members, offset));
                 }
-                copy.rewrite(clazz, GeneratorUtilities.get(copy).insertClassMembers(clazz, members, offset));
             }
         };
     }
@@ -291,7 +340,7 @@ public List<? extends CodeGenerator> create(Lookup context) {
             if (!endpoints.isEmpty()) {
                 int offset = comp.getCaretPosition();
                 FileObject fo = cc.getFileObject();
-                List<ElementHandle<VariableElement>> repositoryHandles = repositories.stream().map(repository -> ElementHandle.create(repository)).collect(Collectors.toList());
+                List<String> repositoryNames = repositories.stream().map(repository -> repository.getSimpleName().toString()).collect(Collectors.toList());
                 ret.add(new CodeGenerator() {
                     @Override
                     public String getDisplayName() {
@@ -320,8 +369,8 @@ public void invoke() {
                             if (js == null) {
                                 throw new IOException("Cannot get JavaSource for: " + fo.toURL().toString());
                             }
-                            js.runModificationTask(getTask(offset, repositoryHandles, selectedEndpoints)).commit();
-                        } catch (Exception ex) {
+                            js.runModificationTask(getTask(offset, repositoryNames, selectedEndpoints)).commit();
+                        } catch (IOException | IllegalArgumentException ex) {
                             Exceptions.printStackTrace(ex);
                         }
                     }
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java
index 28b296d59964..d818c9315f71 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java
@@ -549,7 +549,7 @@ public static WorkspaceEdit workspaceEditFromApi(org.netbeans.api.lsp.WorkspaceE
                 String docUri = parts.first().getDocument();
                 try {
                     FileObject file = Utils.fromUri(docUri);
-                    if (file == null) {
+                    if (file == null && uri != null) {
                         file = Utils.fromUri(uri);
                     }
                     FileObject fo = file;
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider.java
index f9a1378e348f..47eccb3455dd 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider.java
@@ -69,10 +69,14 @@ public CompletableFuture<Object> processCommand(NbCodeLanguageClient client, Str
     }
 
     protected CodeAction createCodeAction(NbCodeLanguageClient client, String name, String kind, Object data, String command, Object... commandArgs) {
+        return createCodeAction(client, name, kind, data, command, Arrays.asList(commandArgs));
+    }
+
+    protected CodeAction createCodeAction(NbCodeLanguageClient client, String name, String kind, Object data, String command, List<Object> commandArgs) {
         CodeAction action = new CodeAction(name);
         action.setKind(kind);
         if (command != null) {
-            action.setCommand(new Command(name, Utils.encodeCommand(command, client.getNbCodeCapabilities()), Arrays.asList(commandArgs)));
+            action.setCommand(new Command(name, Utils.encodeCommand(command, client.getNbCodeCapabilities()), commandArgs));
         }
         if (data != null) {
             Map<String, Object> map = new HashMap<>();
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider2LspApiBridge.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider2LspApiBridge.java
index a901cf1a5d67..7b7f70e9e272 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider2LspApiBridge.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider2LspApiBridge.java
@@ -61,7 +61,12 @@ public Set<String> getCommands() {
     public CompletableFuture<Object> processCommand(NbCodeLanguageClient client, String command, List<Object> arguments) {
         for (CommandProvider cmdProvider : Lookup.getDefault().lookupAll(CommandProvider.class)) {
             if (cmdProvider.getCommands().contains(command)) {
-                return cmdProvider.runCommand(command, arguments);
+                return cmdProvider.runCommand(command, arguments).thenApply(ret -> {
+                    if (ret instanceof WorkspaceEdit) {
+                        return Utils.workspaceEditFromApi((WorkspaceEdit) ret, null, client);
+                    }
+                    return ret;
+                });
             }
         }
         return CompletableFuture.completedFuture(false);
@@ -96,7 +101,7 @@ public List<CodeAction> getCodeActions(NbCodeLanguageClient client, ResultIterat
                         }
                         CodeAction codeAction = createCodeAction(client, ca.getTitle(), ca.getKind(), data, command, command != null ? ca.getCommand().getArguments() : null);
                         if (edit != null) {
-                            codeAction.setEdit(TextDocumentServiceImpl.fromAPI(edit, uri, client));
+                            codeAction.setEdit(Utils.workspaceEditFromApi(edit, uri, client));
                         }
                         allActions.add(codeAction);
                     }
@@ -115,7 +120,7 @@ public CompletableFuture<CodeAction> resolve(NbCodeLanguageClient client, CodeAc
             if (obj.has(URL) && obj.has(INDEX)) {
                 LazyCodeAction inputAction = lastCodeActions.get(obj.getAsJsonPrimitive(INDEX).getAsInt());
                 if (inputAction != null) {
-                    codeAction.setEdit(TextDocumentServiceImpl.fromAPI(inputAction.getLazyEdit().get(), obj.getAsJsonPrimitive(URL).getAsString(), client));
+                    codeAction.setEdit(Utils.workspaceEditFromApi(inputAction.getLazyEdit().get(), obj.getAsJsonPrimitive(URL).getAsString(), client));
                 }
             }
         }
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java
index 1d16573dae6a..583f90585472 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java
@@ -77,6 +77,7 @@
 @ServiceProvider(service = CodeActionsProvider.class, position = 10)
 public final class ConstructorGenerator extends CodeActionsProvider {
 
+    private static final String GENERATE_CONSTRUCTOR = "nbls.java.generate.constructor";
     private static final String URI =  "uri";
     private static final String OFFSET =  "offset";
     private static final String CONSTRUCTORS =  "constructors";
@@ -187,7 +188,12 @@ public List<CodeAction> getCodeActions(NbCodeLanguageClient client, ResultIterat
         data.put(OFFSET, startOffset);
         data.put(CONSTRUCTORS, constructors);
         data.put(FIELDS, fields);
-        return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateConstructor(), isSource ? CODE_GENERATOR_KIND : CodeActionKind.QuickFix, data, "workbench.action.focusActiveEditorGroup"));
+        return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateConstructor(), isSource ? CODE_GENERATOR_KIND : CodeActionKind.QuickFix, null, "nbls.generate.code", GENERATE_CONSTRUCTOR, data));
+    }
+
+    @Override
+    public Set<String> getCommands() {
+        return Collections.singleton(GENERATE_CONSTRUCTOR);
     }
 
     @Override
@@ -195,19 +201,19 @@ public List<CodeAction> getCodeActions(NbCodeLanguageClient client, ResultIterat
         "DN_SelectSuperConstructor=Select super constructor",
         "DN_SelectConstructorFields=Select fields to be initialized by constructor",
     })
-    public CompletableFuture<CodeAction> resolve(NbCodeLanguageClient client, CodeAction codeAction, Object data) {
-        CompletableFuture<CodeAction> future = new CompletableFuture<>();
+    public CompletableFuture<Object> processCommand(NbCodeLanguageClient client, String command, List<Object> arguments) {
+        if (arguments.isEmpty()) {
+            return CompletableFuture.completedFuture(null);
+        }
+        JsonObject data = (JsonObject) arguments.get(0);
+        CompletableFuture<Object> future = new CompletableFuture<>();
         try {
-            String uri = ((JsonObject) data).getAsJsonPrimitive(URI).getAsString();
-            int offset = ((JsonObject) data).getAsJsonPrimitive(OFFSET).getAsInt();
-            List<QuickPickItem> constructors = Arrays.asList(gson.fromJson(((JsonObject) data).get(CONSTRUCTORS), QuickPickItem[].class));
-            List<QuickPickItem> fields = Arrays.asList(gson.fromJson(((JsonObject) data).get(FIELDS), QuickPickItem[].class));
+            String uri = data.getAsJsonPrimitive(URI).getAsString();
+            int offset = data.getAsJsonPrimitive(OFFSET).getAsInt();
+            List<QuickPickItem> constructors = Arrays.asList(gson.fromJson(data.get(CONSTRUCTORS), QuickPickItem[].class));
+            List<QuickPickItem> fields = Arrays.asList(gson.fromJson(data.get(FIELDS), QuickPickItem[].class));
             if (constructors.size() < 2 && fields.isEmpty()) {
-                WorkspaceEdit edit = generate(client, uri, offset, constructors, fields);
-                if (edit != null) {
-                    codeAction.setEdit(edit);
-                }
-                future.complete(codeAction);
+                future.complete(generate(client, uri, offset, constructors, fields));
             } else {
                 InputService.Registry inputServiceRegistry = Lookup.getDefault().lookup(InputService.Registry.class);
                 if (inputServiceRegistry != null) {
@@ -238,18 +244,10 @@ public CompletableFuture<CodeAction> resolve(NbCodeLanguageClient client, CodeAc
                     client.showMultiStepInput(new ShowMutliStepInputParams(inputId, Bundle.DN_GenerateConstructor())).thenAccept(result -> {
                         Either<List<QuickPickItem>, String> selectedConstructors = result.get(CONSTRUCTORS);
                         Either<List<QuickPickItem>, String> selectedFields = result.get(FIELDS);
-                        if (selectedFields != null) {
-                            try {
-                                WorkspaceEdit edit = generate(client, uri, offset, selectedConstructors != null ? selectedConstructors.getLeft() : constructors, selectedFields.getLeft());
-                                if (edit != null) {
-                                    codeAction.setEdit(edit);
-                                }
-                                future.complete(codeAction);
-                            } catch (IOException | IllegalArgumentException ex) {
-                                future.completeExceptionally(ex);
-                            }
-                        } else {
-                            future.complete(codeAction);
+                        try {
+                            future.complete(selectedFields != null ? generate(client, uri, offset, selectedConstructors != null ? selectedConstructors.getLeft() : constructors, selectedFields.getLeft()) : null);
+                        } catch (IOException | IllegalArgumentException ex) {
+                            future.completeExceptionally(ex);
                         }
                     });
                 }
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java
index 6b689ebdeb45..74c4523b85be 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java
@@ -31,6 +31,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 import javax.lang.model.element.Element;
@@ -73,6 +74,7 @@
 @ServiceProvider(service = CodeActionsProvider.class, position = 60)
 public final class DelegateMethodGenerator extends CodeActionsProvider {
 
+    private static final String GENERATE_DELEGATE_METHOD = "nbls.java.generate.delegate";
     private static final String URI =  "uri";
     private static final String OFFSET =  "offset";
     private static final String TYPE =  "type";
@@ -135,7 +137,12 @@ public List<CodeAction> getCodeActions(NbCodeLanguageClient client, ResultIterat
         data.put(OFFSET, offset);
         data.put(TYPE, typeItem);
         data.put(FIELDS, fields);
-        return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateDelegateMethod(), CODE_GENERATOR_KIND, data, "workbench.action.focusActiveEditorGroup"));
+        return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateDelegateMethod(), CODE_GENERATOR_KIND, null, "nbls.generate.code", GENERATE_DELEGATE_METHOD, data));
+    }
+
+    @Override
+    public Set<String> getCommands() {
+        return Collections.singleton(GENERATE_DELEGATE_METHOD);
     }
 
     @Override
@@ -143,13 +150,17 @@ public List<CodeAction> getCodeActions(NbCodeLanguageClient client, ResultIterat
         "DN_SelectDelegateMethodField=Select target field to generate delegates for",
         "DN_SelectDelegateMethods=Select methods to generate delegates for",
     })
-    public CompletableFuture<CodeAction> resolve(NbCodeLanguageClient client, CodeAction codeAction, Object data) {
-        CompletableFuture<CodeAction> future = new CompletableFuture<>();
+    public CompletableFuture<Object> processCommand(NbCodeLanguageClient client, String command, List<Object> arguments) {
+        if (arguments.isEmpty()) {
+            return CompletableFuture.completedFuture(null);
+        }
+        JsonObject data = (JsonObject) arguments.get(0);
+        CompletableFuture<Object> future = new CompletableFuture<>();
         try {
-            String uri = ((JsonObject) data).getAsJsonPrimitive(URI).getAsString();
-            int offset = ((JsonObject) data).getAsJsonPrimitive(OFFSET).getAsInt();
-            QuickPickItem type = gson.fromJson(gson.toJson(((JsonObject) data).get(TYPE)), QuickPickItem.class);
-            List<QuickPickItem> fields = Arrays.asList(gson.fromJson(((JsonObject) data).get(FIELDS), QuickPickItem[].class));
+            String uri = data.getAsJsonPrimitive(URI).getAsString();
+            int offset = data.getAsJsonPrimitive(OFFSET).getAsInt();
+            QuickPickItem type = gson.fromJson(gson.toJson(data.get(TYPE)), QuickPickItem.class);
+            List<QuickPickItem> fields = Arrays.asList(gson.fromJson(data.get(FIELDS), QuickPickItem[].class));
             InputService.Registry inputServiceRegistry = Lookup.getDefault().lookup(InputService.Registry.class);
             if (inputServiceRegistry != null) {
                 int totalSteps = fields.size() > 1 ? 2 : 1;
@@ -220,18 +231,10 @@ public boolean accept(Element e, TypeMirror type) {
                     Either<List<QuickPickItem>, String> selectedFields = result.get(FIELDS);
                     QuickPickItem selectedField = (selectedFields != null ? selectedFields.getLeft() : fields).get(0);
                     Either<List<QuickPickItem>, String> selectedMethods = result.get(METHODS);
-                    if (selectedField != null && selectedMethods != null) {
-                        try {
-                            WorkspaceEdit edit = generate(uri, offset, selectedField, selectedMethods.getLeft());
-                            if (edit != null) {
-                                codeAction.setEdit(edit);
-                            }
-                            future.complete(codeAction);
-                        } catch (IOException | IllegalArgumentException ex) {
-                            future.completeExceptionally(ex);
-                        }
-                    } else {
-                        future.complete(codeAction);
+                    try {
+                        future.complete(selectedField != null && selectedMethods != null ? generate(uri, offset, selectedField, selectedMethods.getLeft()) : null);
+                    } catch (IOException | IllegalArgumentException ex) {

Leaderboard for this case

medium · 5 of 9 bots fully caught it (56% solve rate) · 56% avg coverage.

#BotResultCaughtCoverageFindingsFalse alarms
1 Claude Code (Opus 5.5) solved 1/1 100.0% 4 0
2 Drape (Deep Review) solved 1/1 100.0% 5 0
3 Mjolnir (Opus 5.5) solved 1/1 100.0% 3 0
4 Mjolnir (Sonnet 5.5) solved 1/1 100.0% 1 0
5 qodo solved 1/1 100.0% 2 0
6 cursor miss 0/1 0.0% 1 0
7 Drape (Review) miss 0/1 0.0% 3 0
8 greptile miss 0/1 0.0% 1 0
9 Cubic miss 0/1 0.0% 2 1

Bot results

Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ exact
valid · matches d1 · impact medium
valid · impact medium
Code actions now carry no data, so resolve no longer computes an edit. The only route left is the client-side command nbls.generate.code, which only extension.ts registers; the server's getCommands lists only the nbls.java.generate.* ids. Other LSP clients therefore can't apply these generators. [grounded: diff] [consensus 3/3: valid=3]
valid · impact medium
Inside the RequestProcessor task, runtime exceptions such as IllegalArgumentException from URI.create, JsonSyntaxException from gson, or NPE from getAsJsonPrimitive are not caught. The future then never completes, so the executeCommand request hangs. [grounded: diff] [consensus 3/3: valid=3]
valid · impact low
The diff narrows the catch from Exception to IOException | IllegalArgumentException. Other runtime exceptions from runModificationTask or the task are no longer logged and now propagate out of invoke(). [grounded: diff] [consensus 3/3: valid=3]
raw comments (4)
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:191
The code action's own command ("nbls.generate.code") goes through Utils.encodeCommand, but the inner command passed as its first argument ("nbls.java.generate.constructor") does not. Server.java registers every provider command under its encoded name (Utils.encodeCommand(cmd, capa)). So a client that sets a non-default command prefix registers the generator as "<prefix>.java.generate.constructor". When the client handler for <prefix>.generate.code then calls executeCommand("nbls.java.generate.constructor", data), no command by that name exists and code generation fails. The same problem affects all the generators changed here (Delegate, EqualsHashCode, GetterSetter, ImplementOverride, Logger, ToString) and the Micronaut data endpoint generator.
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java:106
The edit is no longer computed in codeAction/resolve. Every source generator now returns only a command (data=null) whose handler, "nbls.generate.code", exists only in the bundled VS Code extension. Any other LSP client used to get a resolvable edit (for example a single getter/setter, or toString with no fields). Now it gets an unknown command and cannot apply the edit at all.
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:193
runCommand completes the future only for normal results and IOException. Any RuntimeException thrown in the RequestProcessor task is swallowed and the future never completes, so the client's executeCommand request hangs forever. Examples: ClassCastException or NullPointerException from malformed JSON arguments, JsonSyntaxException from gson.fromJson, or IllegalArgumentException from modify2Edit or URI.create.
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:286
This catch was narrowed from Exception to IOException | IllegalArgumentException. Other runtime exceptions from runModificationTask/commit or from the task (for example an unexpected cast) used to be logged. Now they propagate out of the IDE code generator's invoke() on the EDT.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✗ —
invalid · impact low
The bug is real, but the pre-change resolve() also called generate(uri, offset, fields) when selected != null. The change only rewrote the line, so it is pre-existing. [invalid: contradiction] [consensus 5/5: invalid=5]
valid · impact medium
The new async runCommand posts work to RequestProcessor and catches only IOException. A RuntimeException (bad URI, missing JSON key, or an IllegalArgumentException from the modification task) leaves the future uncompleted, so the LSP request hangs. The old code ran the edit synchronously, so the exception propagated instead. [grounded: diff] [consensus 5/5: valid=5]
raw comments (3)
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java:146
<!-- cubic:v=20389fc7-8eec-43b2-9d72-cc7579cd1ce6 --> <!-- cubic:review-run=b78edc2d-61a2-523b-a1a5-9c3f9022a2bb --> <!-- metadata:{"confidence":10} --> P2: When the user selects a subset of fields, this still passes all candidate `fields` to `generate`, so the generated `toString()` ignores the selection. Pass `selected` instead. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java, line 146: <comment>When the user selects a subset of fields, this still passes all candidate `fields` to `generate`, so the generated `toString()` ignores the selection. Pass `selected` instead.</comment> <file context> @@ -114,35 +116,34 @@ public List<CodeAction> getCodeActions(NbCodeLanguageClient client, ResultIterat - } - } - future.complete(codeAction); + future.complete(selected != null ? generate(uri, offset, fields) : null); } catch (IOException | IllegalArgumentException ex) { future.completeExceptionally(ex); </file context> ``` </details> ```suggestion future.complete(selected != null ? generate(uri, offset, selected) : null); ```
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:202
<!-- cubic:v=970e30b6-6a84-47e3-8429-5e377a68641b --> <!-- cubic:review-run=b78edc2d-61a2-523b-a1a5-9c3f9022a2bb --> <!-- metadata:{"confidence":8} --> P2: When a generated command encounters a malformed or stale payload, or an `IllegalArgumentException` during modification, the posted task exits without completing `future`, so the LSP request remains pending. Catch runtime/JSON exceptions in this task and complete the future exceptionally. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java, line 202: <comment>When a generated command encounters a malformed or stale payload, or an `IllegalArgumentException` during modification, the posted task exits without completing `future`, so the LSP request remains pending. Catch runtime/JSON exceptions in this task and complete the future exceptionally.</comment> <file context> @@ -126,79 +147,107 @@ public List<CodeAction> getCodeActions(Document doc, Range range, Lookup context + future.complete(modify2Edit(js, getTask(offset, repositoryNames, selectedIds))); + } + } + } catch (IOException ex) { + future.completeExceptionally(ex); + } </file context> ``` </details> ```suggestion } catch (IOException | RuntimeException ex) { ```
PR-level
<!-- cubic:review-summary:start --> **2 issues found** across 14 files <!-- cubic:review-summary:end --> <details> <summary>Prompt for AI agents (unresolved issues)</summary> ```text Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately. <file name="java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java"> <violation number="1" location="java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java:146"> P2: When the user selects a subset of fields, this still passes all candidate `fields` to `generate`, so the generated `toString()` ignores the selection. Pass `selected` instead.</violation> </file> <file name="enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java"> <violation number="1" location="enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:202"> P2: When a generated command encounters a malformed or stale payload, or an `IllegalArgumentException` during modification, the posted task exits without completing `future`, so the LSP request remains pending. Catch runtime/JSON exceptions in this task and complete the future exceptionally.</violation> </file> ``` </details> <sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/60/ai_pr_review_github_delivery_704cb9ff3a9140ee40b9c79a153c52d5795b603c828545c90067979ad0daf48e?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F60)</sub> <!-- cubic:review-post:ai_pr_review_github_delivery_704cb9ff3a9140ee40b9c79a153c52d5795b603c828545c90067979ad0daf48e:9144110e137cd8cf6436f1c1a55eecfae3c22426:b78edc2d-61a2-523b-a1a5-9c3f9022a2bb -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✗ —
valid · impact low
The new asynchronous runCommand body posted to RequestProcessor only catches IOException. Any runtime exception goes uncaught on the RP thread, and the returned future is never completed. Examples are an NPE from a missing key, IllegalArgumentException from URI.create, JsonSyntaxException from gson, or a runtime failure inside the modification task. The nbls.generate.code caller would then wait forever. This async future pattern is new in this change. [grounded: diff] [consensus 5/5: valid=5]
raw comments (2)
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:204
### Command future can hang indefinitely **Medium Severity** <!-- DESCRIPTION START --> The background task in `runCommand` only completes the returned `CompletableFuture` on success or `IOException`. Other failures such as `IllegalArgumentException`, `JsonSyntaxException`, or `IllegalStateException` while reading `uri`, `offset`, `endpoints`, or `repositories` leave the future unfinished, so `nbls.generate.code` waits forever. <!-- DESCRIPTION END --> <!-- BUGBOT_BUG_ID: 7bdacaa4-aae8-49ea-94a3-3af002e304a6 --> <!-- LOCATIONS START enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java#L174-L204 LOCATIONS END --> <div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjFlNzQ1MjRjLWUwYmEtNGNhOC04ZTQzLWJiYmI3OGU0ZDk5OSIsImVuY3J5cHRpb25LZXkiOiJnT0wtN0JYWHp2R0VBN0tLNmpEbXlqdFA5T2M5UmhNVmxTZlpoZzRmX0ljIiwiYnJhbmNoIjoidDItbmV0YmVhbnMtNjk5MCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjFlNzQ1MjRjLWUwYmEtNGNhOC04ZTQzLWJiYmI3OGU0ZDk5OSIsImVuY3J5cHRpb25LZXkiOiJnT0wtN0JYWHp2R0VBN0tLNmpEbXlqdFA5T2M5UmhNVmxTZlpoZzRmX0ljIiwiYnJhbmNoIjoidDItbmV0YmVhbnMtNjk5MCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjYyLCJjb21taXRTaGEiOiIxYjdhMjI5NTI3ZjM2MWY4MWM1YzViMWVjZTVmN2M4YWI1MmMyN2U2IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1b7a229527f361f81c5c5b1ece5f7c8ab52c27e6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
PR-level
<!-- BUGBOT_REVIEW --> Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue. <!-- BUGBOT_FIX_ALL --> <a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo0ZGRjY2Q2MC0zM2IzLTQxMWEtYTZhMi1kNDJhMzA3ODUyZDMiLCJlbmNyeXB0aW9uS2V5IjoicEV1Y1dhMFYxSmU4MVc2N0E2dTdjS19rSWJLZk9wb0FQS1VvVVBfSzdBMCIsImJyYW5jaCI6InQyLW5ldGJlYW5zLTY5OTAiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <!-- /BUGBOT_FIX_ALL --> <!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN --> <sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup> <!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END --> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1b7a229527f361f81c5c5b1ece5f7c8ab52c27e6. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ exact
valid · impact medium
The new runCommand body runs on a RequestProcessor and only catches IOException. A runtime exception such as IllegalArgumentException from URI.create or a JsonSyntaxException from gson.fromJson escapes the task, so the returned future never completes. [grounded: diff] [consensus 3/3: valid=3]
valid · matches d1 · impact medium
valid · impact low
The catch used to be `catch (Exception ex)` and is now narrower, so other runtime exceptions now propagate out of invoke() instead of being logged through Exceptions.printStackTrace. This is a real behaviour change with limited impact. [grounded: diff] [consensus 3/3: valid=3]
valid · impact medium
The resolve-based edit path was removed. Code actions now carry the command nbls.generate.code, which only the VS Code extension registers on the client side; the server's getCommands lists only the inner nbls.java.generate.* ids. Non-VS Code clients can no longer get the edits, including the non-interactive cases that used to work through resolve. [grounded: diff] [consensus 3/3: valid=3]
valid · impact medium
Previously, single-field getter/setter actions had no command (it was null) and resolved to a plain edit. They now always go through the client-only nbls.generate.code command, which breaks these quick fixes in other LSP clients. [grounded: diff] [consensus 3/3: valid=3]
raw comments (5)
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:200
**Command future never completes on runtime errors** The posted task in `runCommand` catches only `IOException`; a runtime exception (bad URI, `JsonSyntaxException`, NPE during generation) leaves `future` pending, so the client's executeCommand never returns. Catch Exception in the posted task and complete the future exceptionally. ``` enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:175 RequestProcessor.getDefault().post(() -> { enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:176 try { enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:177 String uri = data.getAsJsonPrimitive(URI).getAsString(); enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:178 FileObject fo = URLMapper.findFileObject(java.net.URI.create(uri).toURL()); enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:179 JavaSource js = fo != null ? JavaSource.forFileObject(fo) : null; enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:180 if (js == null) { enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:200 } enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:201 } enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:202 } catch (IOException ex) { enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:203 future.completeExceptionally(ex); ```
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java:140
**Generator command id not prefix-encoded for client** `GENERATE_DELEGATE_METHOD` is passed as an argument without `encodeCommand`. Clients with a non-`nbls` prefix only register the encoded name, so the command cannot be found. Encode the inner command id with the client's prefix. The same mistake is at `java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/EqualsHashCodeGenerator.java:118`, `java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java:106`, `java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ImplementOverrideMethodGenerator.java:112`, `java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java:111`, `java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java:119`, `enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:155` and `java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:191`. ``` java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java:140 return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateDelegateMethod(), CODE_GENERATOR_KIND, null, "nbls.generate.code", GENERATE_DELEGATE_METHOD, data)); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:867 commands = commands.stream().map(cmd -> Utils.encodeCommand(cmd, capa)).collect(Collectors.toSet()); ```
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:373
**Narrowed catch lets generator errors escape** In the IDE code generator's `invoke`, the catch was narrowed from `Exception` to `IOException | IllegalArgumentException`. Runtime failures from the modification task (e.g. NPE, ClassCastException) now reach the editor's Insert Code action instead of being logged. Keep catching Exception here. ``` enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:373 } catch (IOException | IllegalArgumentException ex) { enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:324 (base) } catch (Exception ex) { ```
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:191
**Code generators broken for generic LSP clients** Generators now depend on a client-side `nbls.generate.code` command that only this VS Code extension registers. Standard LSP clients that used codeAction/resolve can no longer run any generator. Keep the resolve-based path as a fallback, or gate the new command on a client capability. ``` java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:191 return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateConstructor(), isSource ? CODE_GENERATOR_KIND : CodeActionKind.QuickFix, null, "nbls.generate.code", GENERATE_CONSTRUCTOR, data)); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:190 (base) return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateConstructor(), isSource ? CODE_GENERATOR_KIND : CodeActionKind.QuickFix, data, "workbench.action.focusActiveEditorGroup")); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:863 for (CodeActionsProvider codeActionsProvider : Lookup.getDefault().lookupAll(CodeActionsProvider.class)) { java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:864 commands.addAll(codeActionsProvider.getCommands()); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:865 } java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:866 Utils.ensureCommandsPrefixed(commands); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:867 commands = commands.stream().map(cmd -> Utils.encodeCommand(cmd, capa)).collect(Collectors.toSet()); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:868 capabilities.setExecuteCommandProvider(new ExecuteCommandOptions(new ArrayList<>(commands))); java/java.lsp.server/vscode/src/extension.ts:558 context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.generate.code', async (command, data) => { ```
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java:106
**Simple getter/setter quick fixes break outside VS Code** Single-field getter/setter (and toString with no fields) used to resolve to a plain edit. Now they need a client-side `nbls.generate.code` command that only the VS Code extension registers. Keep returning the edit directly when no prompt is needed. ``` java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java:106 result.add(createCodeAction(client, name, all ? CODE_GENERATOR_KIND : CodeActionKind.QuickFix, null, "nbls.generate.code", GENERATE_GETTER_SETTER, data(GeneratorUtils.GETTERS_ONLY, uri, offset, all, pair.first().stream().map(variableElement -> { java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java:107 QuickPickItem item = new QuickPickItem(createLabel(info, variableElement)); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java:108 item.setUserData(new ElementData(variableElement)); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java:109 return item; java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:863 for (CodeActionsProvider codeActionsProvider : Lookup.getDefault().lookupAll(CodeActionsProvider.class)) { java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:864 commands.addAll(codeActionsProvider.getCommands()); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:865 } java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:866 Utils.ensureCommandsPrefixed(commands); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:867 commands = commands.stream().map(cmd -> Utils.encodeCommand(cmd, capa)).collect(Collectors.toSet()); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java:868 capabilities.setExecuteCommandProvider(new ExecuteCommandOptions(new ArrayList<>(commands))); ```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✗ —
valid · impact medium
The new RequestProcessor task only catches IOException. URI.create can throw IllegalArgumentException, and a missing JSON field causes an NPE. modify2Edit or the task can also throw runtime exceptions. Any of these leaves the future uncompleted, so the command hangs. [grounded: diff] [consensus 3/3: valid=3]
valid · impact low
createCodeAction encodes only the outer command. The inner 'nbls.java.generate.*' id is passed through as a raw argument, and the client executes it directly. A client using a non-default prefix would call a command name it never registered. [grounded: diff] [consensus 3/3: valid=3]
valid · impact low
WorkspaceServiceImpl passes params.getArguments() straight through, and LSP4J returns null for it when the client omits arguments. The new processCommand methods then dereference it without a null check and throw an NPE. This only affects malformed invocations, so the impact is low. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:172
**Generate endpoint command hangs on runtime errors** `runCommand` posts work to a RequestProcessor and only catches `IOException`. Any runtime exception (bad URI, missing JSON field, failure inside `modify2Edit`) is swallowed and the returned future is never completed. Catch RuntimeException too and call future.completeExceptionally(ex). ``` enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:176 try { enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:177 String uri = data.getAsJsonPrimitive(URI).getAsString(); enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:178 FileObject fo = URLMapper.findFileObject(java.net.URI.create(uri).toURL()); enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:200 } enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:201 } enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:202 } catch (IOException ex) { ```
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:191
**Inner generator command name not re-prefixed for client** The generator command id (e.g. `nbls.java.generate.constructor`) is passed as an argument of `nbls.generate.code`, so `encodeCommand` never rewrites it. A client with a custom command prefix then runs an unregistered command. Encode the inner command with `Utils.encodeCommand` before passing it as an argument. ``` java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:191 return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateConstructor(), isSource ? CODE_GENERATOR_KIND : CodeActionKind.QuickFix, null, "nbls.generate.code", GENERATE_CONSTRUCTOR, data)); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java:510 public static String encodeCommand(String cmd, NbCodeClientCapabilities capa) { java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java:511 String prefix = capa != null ? capa.getCommandPrefix() java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java:512 : DEFAULT_COMMAND_PREFIX; java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java:514 if (cmd.startsWith(DEFAULT_COMMAND_PREFIX) && java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java:515 !DEFAULT_COMMAND_PREFIX.equals(prefix)) { java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java:516 return prefix + cmd.substring(DEFAULT_COMMAND_PREFIX.length()); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java:517 } else { java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java:518 return cmd; java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java:519 } ```
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java:125
**NPE when command is sent without arguments** `processCommand` calls `arguments.isEmpty()` without a null check. LSP4J's `ExecuteCommandParams.getArguments()` is null when the client omits `arguments`. The same pattern is in all the generators and in Micronaut's `runCommand`. Check `arguments == null || arguments.isEmpty()`. ``` java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java:125 return CompletableFuture.completedFuture(null); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java:126 } java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java:127 JsonObject data = (JsonObject) arguments.get(0); java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java:794 return codeActionsProvider.processCommand(client, command, params.getArguments()); ```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✗ —
valid · impact medium
A repo-wide search shows `nbls.generate.code` is registered only in the VS Code extension (`extension.ts`). No server-side CodeActionsProvider or CommandProvider lists it in getCommands. Before this change the edit came back through codeAction resolve, which any LSP client can use. Now the generators send no edit and depend on a command that exists only on the VS Code side, so other clients lose these features. [grounded: diff] [consensus 3/3: valid=3]
raw comments (2)
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java:106
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Wrapper Breaks Generic Clients** The generated code action now invokes `nbls.generate.code`, but that wrapper is implemented only by the bundled VS Code extension. When another LSP client sends this command through `workspace/executeCommand`, the language server does not advertise or handle it and rejects it as unsupported. As a result, getter/setter generation—and the other generators migrated to the same wrapper—no longer works in standard LSP clients. Please retain a server-side execution path or continue exposing the edit through standard code-action resolution.
PR-level
<h3>Greptile Summary</h3> This PR migrates Java and Micronaut code generation from lazy/resolved code-action edits to commands that return workspace edits, adds a VS Code wrapper that applies those edits, and centralizes API-to-LSP workspace-edit conversion. - Adds individual server commands for constructors, accessors, delegation, equality, overrides, loggers, `toString`, and Micronaut endpoints. - Converts command-returned API workspace edits before returning them over LSP. - Updates server tests to execute the underlying generation commands. - Introduces a compatibility regression for LSP clients other than the bundled VS Code extension because the new wrapper command is extension-local. <h3>Confidence Score: 4/5</h3> The PR is not safe to merge until generated code actions retain a standards-compatible execution path for non-VS-Code LSP clients. One shared compatibility defect blocks all migrated generators outside the bundled VS Code extension: their public code actions invoke a wrapper command that the language server does not advertise or implement. **Files Needing Attention:** java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java, the other migrated generator classes, and java/java.lsp.server/vscode/src/extension.ts <details><summary><h3>Important Files Changed</h3></summary> | Filename | Overview | |----------|----------| | java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider2LspApiBridge.java | Converts API workspace edits returned by command providers and bridges API code actions into protocol actions. | | java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java | Representative generator migrated from resolvable code-action edits to an extension-only wrapper command, breaking generic LSP execution. | | enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java | Migrates endpoint generation to delayed command execution and shares the wrapper-command compatibility problem. | | java/java.lsp.server/vscode/src/extension.ts | Adds the VS Code-local wrapper that forwards generator commands, converts returned edits, and applies them. | | java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java | Updates generator tests for command-returned edits but bypasses execution of the public wrapper command, leaving generic-client compatibility uncovered. | </details> <details open><summary><h3>Sequence Diagram</h3></summary> ```mermaid sequenceDiagram participant C as LSP Client participant S as Language Server participant V as VS Code Extension participant G as Generator Command S-->>C: CodeAction(command: nbls.generate.code) alt Bundled VS Code extension C->>V: Execute nbls.generate.code V->>S: workspace/executeCommand(generator command) S->>G: processCommand(data) G-->>S: WorkspaceEdit S-->>V: Protocol WorkspaceEdit V->>C: workspace.applyEdit else Standard LSP client C->>S: workspace/executeCommand(nbls.generate.code) S-->>C: Unsupported command end ``` </details> <!-- greptile_other_comments_section --> <sub>Reviews (1): Last reviewed commit: ["Update enterprise/micronaut/src/org/netb..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/a1cb986347430013433219fbb8811f63976c50d8) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284692)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ exact
valid · matches d1 · impact medium
valid · impact low
The new runCommand catches only IOException inside the RequestProcessor task. A runtime exception, such as an IllegalArgumentException from URI.create or a ClassCastException or NPE from malformed JSON, escapes and is swallowed, so the returned future never completes. [grounded: diff] [consensus 3/3: valid=3]
valid · impact low
Server.java encodes every advertised command with the client's prefix, and WorkspaceServiceImpl decodes the prefix on execute. The inner command ID is passed as a raw 'nbls.*' argument and is never encoded, so a client with a non-default prefix would execute an unregistered command name. This only affects non-default-prefix clients; the bundled VS Code extension uses 'nbls'. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:191
[P2] Inner generator command ID is not encoded with the client's command prefix The outer `nbls.generate.code` command goes through `Utils.encodeCommand` inside `createCodeAction`. The inner command ID (`GENERATE_CONSTRUCTOR`, i.e. `nbls.java.generate.constructor`) is passed as a plain argument, so it is never encoded. `Server` advertises every `getCommands()` entry under its encoded name (`commands.stream().map(cmd -› Utils.encodeCommand(cmd, capa))`), and the client-side handler calls `commands.executeCommand(command, data)` with the raw `nbls.…` string. A client that negotiates a non-default `commandPrefix` (e.g. `foo`) registers `foo.generate.code` and `foo.java.generate.constructor`. When it runs the action, it tries to execute `nbls.java.generate.constructor`, which is not registered, and the action fails. The same pattern applies in every generator changed here (`DelegateMethodGenerator`, `EqualsHashCodeGenerator`, `GetterSetterGenerator`, `ImplementOverrideMethodGenerator`, `LoggerGenerator`, `ToStringGenerator`) and in `MicronautDataEndpointGenerator`. The default `nbls` prefix used by the bundled VS Code extension is unaffected.
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:203
[P3] Micronaut `runCommand` future never completes on a runtime exception The `RequestProcessor` task completes the future exceptionally only for `IOException`. If anything else is thrown, `RequestProcessor` logs and swallows it, and the returned `CompletableFuture` never completes. Examples are an `IllegalArgumentException` from `URI.create` or from the modification task, or an NPE/`ClassCastException` from malformed JSON arguments. The `nbls.generate.code` call in VS Code then waits forever with no edit and no error. This PR's own change to the `CodeGenerator` path (`catch (IOException | IllegalArgumentException ex)`) and the java.lsp.server generators both treat `IllegalArgumentException` as an expected failure, so this handler should complete the future for at least the same cases (or catch `Exception`).
PR-level
[P2] Inner generator command ID is passed without the client command prefix java/java.lsp.server/vscode/src/extension.ts:558-559 The outer `nbls.generate.code` command goes through `Utils.encodeCommand`, and `Server` advertises every `getCommands()` entry with the client's prefix (`Server.java:864-867`). The inner command ID, though, is passed as a raw argument: `nbls.java.generate.constructor`, `nbls.java.generate.getter.setter`, `nbls.micronaut.generate.data.endpoint`, and so on, set in each generator's `createCodeAction(..., "nbls.generate.code", GENERATE_XXX, data)`. The handler here then calls `commands.executeCommand(command, data)` with that unprefixed ID. This only affects clients that declare a non-default `commandPrefix` capability (prefix support exists for that case). For those clients, the language client registers the server commands under the client's prefix (for example `jdk.java.generate.constructor`), so the `nbls.java...` ID is not a registered command. Every Generate code action (constructor, getters/setters, equals/hashCode, toString, delegate, override, logger, Micronaut data endpoint) would then fail with "command not found". Before this change these actions worked through codeAction/resolve. The inner command name should be encoded with `Utils.encodeCommand`, or the handler should call the server's execute-command request directly.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ exact
valid · matches d1 · impact medium
raw comments (1)
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:191
[P2] Inner command ID is not prefix-encoded for non-default client prefixes Every generator now emits the command `nbls.generate.code` with the real command name (here `nbls.java.generate.constructor`) as its first argument. Only the outer command goes through `Utils.encodeCommand`, which rewrites the `nbls` prefix to the client's prefix. The advertised commands in `Server.java:867` are encoded the same way. The inner name is passed through unchanged. The client's `.generate.code` handler in extension.ts (~line 558) calls `commands.executeCommand(command, data)` with that unencoded string. For a client whose `getCommandPrefix()` isn't `nbls` (the encode/decode logic exists for such clients, e.g. an alternative-prefix VS Code extension), only the prefixed command is registered by the language client. The inner call would then fail with "command not found" and the generator would do nothing. The default `nbls` extension is unaffected. The same pattern is in the other Generator classes (DelegateMethod, EqualsHashCode, GetterSetter, ImplementOverrideMethod, Logger, ToString) and in `MicronautDataEndpointGenerator` (`new Command(..., "nbls.generate.code", Arrays.asList(GENERATE_DATA_ENDPOINT, data))`). The fix is to encode the inner command with `Utils.encodeCommand(..., client.getNbCodeCapabilities())` when building the arguments. Alternatively, the client could decode it before executing.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 medium ✓ off by one
valid · matches d1 · impact medium
valid · impact low
The new `runCommand` creates a `CompletableFuture` by hand and fills it inside `RequestProcessor.post`. The only exception it catches there is `IOException`. A runtime exception thrown in that worker never completes the future, so the command request stays pending. Examples are `IllegalArgumentException` from `URI.create`, `JsonSyntaxException` from gson, or a runtime error during edit generation. This async code is new in this change; the code it replaced ran synchronously. Most inputs are generated by the server itself, so this is uncommon, but the hang is real when it happens. [grounded: diff] [consensus 3/3: valid=3]
raw comments (4)
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java:191
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required"> 1\. Code generators fail in other editors <code>🐞 Bug</code> <code>≡ Correctness</code> <pre> <b><i>getCodeActions</i></b> now emits the client-only <b><i>nbls.generate.code</i></b> wrapper instead of retaining resolvable edit data or targeting an advertised server command. Only the bundled VS Code extension registers that wrapper, so another LSP client sends it to <b><i>workspace/executeCommand</i></b>, where the server rejects it as unsupported before any generator runs. </pre> <details> <summary><strong>Agent Prompt</strong></summary> ``` ## Issue description Generator code actions now depend on the VS Code-only `nbls.generate.code` wrapper. Other LSP clients cannot execute that wrapper because the language server neither advertises nor handles it. ## Fix Focus Areas - java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java[188-196] - java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider.java[71-85] - java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java[791-798] - java/java.lsp.server/vscode/src/extension.ts[558-565] ## Recommended Fix Retain the command-wrapper behavior only when the client explicitly advertises support for it, and preserve the previous resolvable-code-action path for generic LSP clients. Apply the same capability-aware construction to every generator migrated to `nbls.generate.code`, including the Micronaut endpoint generator. ``` <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> </details>
enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java:204
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended"> 2\. Malformed endpoint requests never finish <code>🐞 Bug</code> <code>☼ Reliability</code> <pre> <b><i>MicronautDataEndpointGenerator.runCommand</i></b> schedules command processing on a <b><i>RequestProcessor</i></b> but catches only <b><i>IOException</i></b> before completing its manually created future. A malformed URI or JSON payload, a non-object argument, or another runtime failure escapes the worker without completing that future, leaving the client command request pending. </pre> <details> <summary><strong>Agent Prompt</strong></summary> ``` Issue description `runCommand` performs asynchronous parsing and generation but only completes its result future exceptionally for `IOException`. Runtime failures in URI parsing, JSON decoding, or edit generation can escape the worker and leave the command request unresolved. Fix Focus Areas - enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java[169-205] Recommended Fix Wrap all asynchronous command processing in a catch that completes `future` exceptionally for runtime failures as well as `IOException`; also ensure argument casting/parsing is covered or converted to an already failed future. ``` <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> </details>
PR-level
<h3>PR Summary by Qodo</h3> Execute Java code generators through explicit LSP commands <code>🐞 Bug fix</code> <code>🧪 Tests</code> <code>🕐 40+ Minutes</code> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <details> <summary>AI Description</summary> <dl> <dd> <br/> ><pre> >• Route Java and Micronaut generators through explicit LSP command execution. >• Convert returned workspace edits centrally and apply them in the VS Code client. >• Update server tests for command-driven generation. ></pre> </dd> </dl> </details> <details> <summary>Diagram</summary> <dl> <dd> <br/> ```mermaid sequenceDiagram actor user as User participant ext as VS Code participant bridge as LSP Bridge participant gen as Generator participant ui as Input UI participant ws as Workspace user->>ext: Invoke action ext->>bridge: Execute generator bridge->>gen: Dispatch command gen->>ui: Request selection ui-->>gen: Return choices gen-->>bridge: API workspace edit bridge-->>ext: Protocol workspace edit ext->>ws: Apply edit ``` </dd> </dl> </details> <details> <summary>High-Level Assessment</summary> <dl> <dd> <br/> >The following are alternative approaches to this PR: <details> <summary><b>1. Retain lazy code-action resolution</b></summary> <dl> <dd> - ➕ Uses standard code-action resolve semantics - ➕ Avoids introducing generator-specific command identifiers - ➖ Interactive prompts during resolution are difficult for clients to coordinate - ➖ Resolved edits were not reliably applied through the affected client flow </dd> </dl> </details> <details> <summary><b>2. Apply edits from the language server</b></summary> <dl> <dd> - ➕ Avoids a VS Code wrapper command for edit application - ➕ Keeps generation orchestration entirely server-side - ➖ Requires server-initiated workspace/applyEdit handling - ➖ Reduces client control over edit conversion, application, and focus restoration </dd> </dl> </details> >**Recommendation:** Keep the explicit command-returned-edit approach. It cleanly separates interactive generation from code-action resolution, supports both Java-specific and generic API generators, and lets the client own workspace mutation and focus restoration. Centralizing API-to-protocol edit conversion also avoids duplicated behavior. </dd> </dl> </details> <details> <summary> Files changed (14) <code> +371 / -251 </code> </summary> <dl> <dd> <br/> <details> <summary>Enhancement (1) <code> +8 / -3 </code></summary> <dl> <dd> <details> <summary>CodeActionsProvider2LspApiBridge.java<code>Convert workspace edits returned by command providers</code> <code>+8/-3</code></summary> <br/> >Convert workspace edits returned by command providers > ><pre> >• Converts API WorkspaceEdit results from generic CommandProvider executions into protocol workspace edits. It also centralizes conversion for eager and lazy code-action edits through the shared utility. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-5566af7cf5dd6d5b7487ad704971e8ab9fd6cb3dc12852186fffa3fdd0a9227d'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider2LspApiBridge.java</a> </details> </dd> </dl> </details> <details> <summary>Bug fix (10) <code> +275 / -195 </code></summary> <dl> <dd> <details> <summary>MicronautDataEndpointGenerator.java<code>Run Micronaut endpoint generation as an LSP command</code> <code>+110/-61</code></summary> <br/> >Run Micronaut endpoint generation as an LSP command > ><pre> >• Registers the endpoint generator as a CommandProvider and emits a command-backed code action containing URI, offset, repository names, and endpoint choices. The asynchronous command prompts for endpoints, resolves repository fields by name, and returns the generated workspace edit while preserving the editor code-generator path. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-f13f0ea7a1daa150746b8952959641b977650b13b6c2ac1c17c48750b0bfe135'>enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java</a> </details> <details> <summary>Utils.java<code>Guard workspace-edit URI fallback</code> <code>+1/-1</code></summary> <br/> >Guard workspace-edit URI fallback > ><pre> >• Only attempts fallback URI resolution when a fallback URI is available, preventing null URI conversion during workspace-edit processing. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-a85df6239fc29ac83d718573cd95583b19a5605d3cfe5997b077edc65452d926'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/Utils.java</a> </details> <details> <summary>ConstructorGenerator.java<code>Move constructor generation to command execution</code> <code>+22/-24</code></summary> <br/> >Move constructor generation to command execution > ><pre> >• Exposes a dedicated constructor-generation command and changes code actions to invoke the shared generation wrapper. Interactive constructor and field selection now returns a WorkspaceEdit directly from command processing. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-a1e318310c06dda2d3ed2b1f6138a75f2300513c49b275b87906392945c68028'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java</a> </details> <details> <summary>DelegateMethodGenerator.java<code>Move delegate generation to command execution</code> <code>+22/-19</code></summary> <br/> >Move delegate generation to command execution > ><pre> >• Registers a delegate-method command and migrates field and method selection from code-action resolution to command processing. Successful generation returns a WorkspaceEdit directly. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-366ffcd2ae0c09a5ef9086b8a348171b7cd67fdb26d389bea400a06c1916a12e'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java</a> </details> <details> <summary>EqualsHashCodeGenerator.java<code>Move equals and hashCode generation to commands</code> <code>+23/-13</code></summary> <br/> >Move equals and hashCode generation to commands > ><pre> >• Routes equals, hashCode, and combined generation actions through a dedicated command. Selected-field generation now returns a WorkspaceEdit instead of mutating a resolved CodeAction. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-6ded2ea8059f0b9d83b38a5e6f4c6047fdde10a07f2cf85773526d57429eb484'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/EqualsHashCodeGenerator.java</a> </details> <details> <summary>GetterSetterGenerator.java<code>Move accessor generation to command execution</code> <code>+25/-25</code></summary> <br/> >Move accessor generation to command execution > ><pre> >• Routes getter, setter, and combined accessor actions through one dedicated command. Quick-pick handling now completes with the generated WorkspaceEdit or null when cancelled. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-0b4ca5cdbbc9c31feedb25e413572c282c2062eacc0e1b757ba2ba27d2fc82c0'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/GetterSetterGenerator.java</a> </details> <details> <summary>ImplementOverrideMethodGenerator.java<code>Move implement and override generation to commands</code> <code>+20/-15</code></summary> <br/> >Move implement and override generation to commands > ><pre> >• Registers a shared command for implement and override actions. Method selection and source generation now execute through command processing and return the resulting WorkspaceEdit. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-ef1e147050188eb9f4dc483b1deb47b0fa5b3136623b5ace163678fb814e97d3'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ImplementOverrideMethodGenerator.java</a> </details> <details> <summary>LoggerGenerator.java<code>Move logger generation to command execution</code> <code>+19/-9</code></summary> <br/> >Move logger generation to command execution > ><pre> >• Adds a dedicated logger-generation command and moves logger-name prompting out of code-action resolution. Valid input now produces and returns a WorkspaceEdit directly. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-072551e247cf6e4425b82527a52c6a12a5d40adf4ad74c6895c7a5ad7242759b'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LoggerGenerator.java</a> </details> <details> <summary>ToStringGenerator.java<code>Move toString generation to command execution</code> <code>+19/-18</code></summary> <br/> >Move toString generation to command execution > ><pre> >• Registers a toString generation command and routes source actions through the shared wrapper. Field selection now returns the generated WorkspaceEdit from command processing. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-fecbad7305097703f1dc73ce755d80e0a763e042c10fa792a6d8a62fea2db6f5'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ToStringGenerator.java</a> </details> <details> <summary>extension.ts<code>Apply workspace edits returned by generator commands</code> <code>+14/-10</code></summary> <br/> >Apply workspace edits returned by generator commands > ><pre> >• Registers the generate-code wrapper command, executes provider commands, converts returned protocol edits, applies them, and restores editor focus. Surround-with edit conversion is modernized, and the database command uses the shared command prefix. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-89cb5a563e47f4b486e013fecb1bf18faa68e1f38fc146e7426c04647e71006b'>java/java.lsp.server/vscode/src/extension.ts</a> </details> </dd> </dl> </details> <details> <summary>Refactor (2) <code> +7 / -33 </code></summary> <dl> <dd> <details> <summary>CodeActionsProvider.java<code>Support list-based code-action command arguments</code> <code>+5/-1</code></summary> <br/> >Support list-based code-action command arguments > ><pre> >• Adds a command-construction overload accepting an existing argument list. This preserves structured generator command arguments without varargs wrapping. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-ec7b280867f06b8a990e63c6c33dd672d24db16d39282cd5fbfaac2d90c2f327'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider.java</a> </details> <details> <summary>TextDocumentServiceImpl.java<code>Centralize code-action workspace-edit conversion</code> <code>+2/-32</code></summary> <br/> >Centralize code-action workspace-edit conversion > ><pre> >• Replaces local workspace-edit conversion calls with the shared Utils implementation for eager and lazy actions. The duplicated conversion method is removed. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-c1ecb8beabe2b3baf0fa0a75452d8534ddecac420eb057cc59eb980d0890c5f7'>java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java</a> </details> </dd> </dl> </details> <details> <summary>Tests (1) <code> +81 / -20 </code></summary> <dl> <dd> <details> <summary>ServerTest.java<code>Test command-driven source generation</code> <code>+81/-20</code></summary> <br/> >Test command-driven source generation > ><pre> >• Updates generator tests to assert the nbls.generate.code command contract, execute the embedded provider command, and validate the returned WorkspaceEdit. Interactive tests now read selection data from command arguments. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-d0063a429454dffe93be9561f323c2b1ac7788d561d01243d879429822dbe100'>java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/protocol/ServerTest.java</a> </details> </dd> </dl> </details> </dd> </dl> </details>
PR-level
<h3>Code Review by Qodo</h3> <code>🐞 Bugs (2)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <br/> <img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required"> <details> <summary> 1. Code generators fail in other editors <code>🐞 Bug</code> <code>≡ Correctness</code></summary> <br/> > <details open> ><summary>Description</summary> ><br/> > ><pre> ><b><i>getCodeActions</i></b> now emits the client-only <b><i>nbls.generate.code</i></b> wrapper instead of retaining >resolvable edit data or targeting an advertised server command. Only the bundled VS Code extension >registers that wrapper, so another LSP client sends it to <b><i>workspace/executeCommand</i></b>, where the >server rejects it as unsupported before any generator runs. ></pre> ></details> > <details> ><summary>Code</summary> ><br/> > ><code>[java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java[191]](https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-a1e318310c06dda2d3ed2b1f6138a75f2300513c49b275b87906392945c68028R191-R191)</code> > >```diff >+ return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateConstructor(), isSource ? CODE_GENERATOR_KIND : CodeActionKind.QuickFix, null, "nbls.generate.code", GENERATE_CONSTRUCTOR, data)); >``` ></details> > <details> ><summary>Evidence</summary> ><br/> > ><pre> >The constructor action targets <b><i>nbls.generate.code</i></b>, while its provider advertises only ><b><i>nbls.java.generate.constructor</i></b>. Server capabilities aggregate only provider commands, and command >dispatch throws when no provider advertises the received command; the sole implementation of the >wrapper is in the bundled VS Code extension. ></pre> > > <code>[java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java[188-196]](https://github.com/drape-io/crbench-qodo-2026-09/blob/5134a541589626a92f73341a934aeb2ddcacd833/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java/#L188-L196)</code> > <code>[java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java[863-868]](https://github.com/drape-io/crbench-qodo-2026-09/blob/5134a541589626a92f73341a934aeb2ddcacd833/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/Server.java/#L863-L868)</code> > <code>[java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java[791-798]](https://github.com/drape-io/crbench-qodo-2026-09/blob/5134a541589626a92f73341a934aeb2ddcacd833/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java/#L791-L798)</code> > <code>[java/java.lsp.server/vscode/src/extension.ts[558-565]](https://github.com/drape-io/crbench-qodo-2026-09/blob/5134a541589626a92f73341a934aeb2ddcacd833/java/java.lsp.server/vscode/src/extension.ts/#L558-L565)</code> ></details> > <details> ><summary>Agent prompt</summary> ><br/> > >``` >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >Generator code actions now depend on the VS Code-only `nbls.generate.code` wrapper. Other LSP clients cannot execute that wrapper because the language server neither advertises nor handles it. > >## Fix Focus Areas >- java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java[188-196] >- java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeActionsProvider.java[71-85] >- java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java[791-798] >- java/java.lsp.server/vscode/src/extension.ts[558-565] > >## Recommended Fix >Retain the command-wrapper behavior only when the client explicitly advertises support for it, and preserve the previous resolvable-code-action path for generic LSP clients. Apply the same capability-aware construction to every generator migrated to `nbls.generate.code`, including the Micronaut endpoint generator. >``` > <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> ></details> <hr/> </details> <br/> <img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended"> <details> <summary> 2. Malformed endpoint requests never finish <code>🐞 Bug</code> <code>☼ Reliability</code></summary> <br/> > <details open> ><summary>Description</summary> ><br/> > ><pre> ><b><i>MicronautDataEndpointGenerator.runCommand</i></b> schedules command processing on a <b><i>RequestProcessor</i></b> but >catches only <b><i>IOException</i></b> before completing its manually created future. A malformed URI or JSON >payload, a non-object argument, or another runtime failure escapes the worker without completing >that future, leaving the client command request pending. ></pre> ></details> > <details> ><summary>Code</summary> ><br/> > ><code>[enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java[R202-204]](https://github.com/drape-io/crbench-qodo-2026-09/pull/96/files#diff-f13f0ea7a1daa150746b8952959641b977650b13b6c2ac1c17c48750b0bfe135R202-R204)</code> > >```diff >+ } catch (IOException ex) { >+ future.completeExceptionally(ex); >+ } >``` ></details> > <details> ><summary>Evidence</summary> ><br/> > ><pre> >The new handler creates and returns a manually completed future, then moves parsing, URI conversion, >and edit generation onto a background runnable. Those operations can throw runtime exceptions, but >the only completion in the failure path handles <b><i>IOException</i></b>, so such failures do not settle the >returned future. ></pre> > > <code>[enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java[169-205]](https://github.com/drape-io/crbench-qodo-2026-09/blob/5134a541589626a92f73341a934aeb2ddcacd833/enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java/#L169-L205)</code> > <code>[enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java[177-199]](https://github.com/drape-io/crbench-qodo-2026-09/blob/5134a541589626a92f73341a934aeb2ddcacd833/enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java/#L177-L199)</code> ></details> > <details> ><summary>Agent prompt</summary> ><br/> > >``` >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >Issue description >`runCommand` performs asynchronous parsing and generation but only completes its result future exceptionally for `IOException`. Runtime failures in URI parsing, JSON decoding, or edit generation can escape the worker and leave the command request unresolved. > >Fix Focus Areas >- enterprise/micronaut/src/org/netbeans/modules/micronaut/db/MicronautDataEndpointGenerator.java[169-205] > >Recommended Fix >Wrap all asynchronous command processing in a catch that completes `future` exceptionally for runtime failures as well as `IOException`; also ensure argument casting/parsing is covered or converted to an already failed future. >``` > <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code> ></details> <hr/> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-context:start --> <details><summary><strong>Context sources</strong></summary> <div>Review mode: <code>🧠 Deep</code>: This is a broad, behavior-changing LSP command migration across many independent generators, server conversion paths, Micronaut code actions, and VS Code integration, creating a high density of subtle cross-component defects.</div> <!-- qodo-context:end --> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-daily-tip:start --> <details> <summary><strong>Tip of the day</strong></summary> <br/> <pre>💡 Did you know, you can reply &#x27;qodo&#x27; on any finding to push back, ask questions, or dig deeper</pre> <a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a> </details> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <!-- qodo-daily-tip:end --> <!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/5134a541589626a92f73341a934aeb2ddcacd833 --> <a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>