Skip to content

editCode tool fails with empty selectors on large Java files #7073

@ghdefe

Description

@ghdefe

Before opening, please confirm:

Operating System

Windows 10

Kiro Version

0.11.63

Bug Description

The editCode tool (AST-based code editing) has multiple issues when operating on large Java files (~390+ lines):

Issue 1: Empty selectors - insert_node/replace_node fail
All selector formats return an empty list:

Error: Could not find target: AffiliateTradePanelServiceImpl. Available selectors: 

Tried selectors:

  • Unscoped method name: checkAffiliateToPermission
  • Scoped: AffiliateTradePanelServiceImpl.checkAffiliateToPermission
  • Class name: AffiliateTradePanelServiceImpl

Issue 2: delete_node corrupts file
delete_node with selector AffiliateTradePanelServiceImpl.healthCheck reported success but actually deleted the entire class body, leaving only imports and a stray }. File had to be restored via git checkout.

Issue 3: False negative on write verification
When using insert_node, the tool reports Write verification failed - changes were not applied to file, but changes were actually written successfully. This causes the agent to believe the operation failed and attempt alternative approaches (e.g. strReplace), resulting in duplicate or conflicting edits. The agent ends up modifying already-modified content, potentially causing further corruption.

Note: semanticRename and getDiagnostics (which use LSP/JDT) work perfectly on the same file.

Steps to Reproduce

  1. Open a large Java file (~390 lines) with many imports (~45), Lombok annotations (@slf4j, @requiredargsconstructor), and Spring annotations (@value, @OverRide)
  2. Ask the agent to use editCode with insert_node operation to add a method
  3. Try any selector format - all fail with empty selectors list
  4. All return: Error: Could not find target: XXX. Available selectors: (empty list)
  5. Try delete_node - reports success but deletes entire class body
  6. Try insert_node - reports "Write verification failed" but file is actually modified
  7. Agent retries with strReplace, causing duplicate edits

Expected Behavior

  1. AST parser should correctly parse the Java file and find all class/method selectors
  2. insert_node should insert the method without corrupting the file
  3. delete_node should only delete the targeted method, not the entire class body
  4. Write verification should accurately reflect whether changes were applied

For reference, semanticRename and getDiagnostics (which use LSP/JDT Language Server) work perfectly on the same file.

Conversation ID

No response

Additional Context

Environment details:

  • Kiro 0.11.63 (user setup), VSCode 1.107.1
  • OS: Windows_NT x64 10.0.19045
  • Electron: 39.6.0, Node.js: 22.22.0
  • Java 11, Spring Boot 2.6.3, Gradle multi-project

File characteristics:

Workaround: Use strReplace instead of editCode for Java files.

Suggestion: Consider leveraging LSP (JDT Language Server) for AST operations on Java files, similar to how semanticRename and getDiagnostics already use LSP successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions