apache / apache/netbeans

Fixing imports deletes a comment line

Open
#7,964 3 comments 0 reactions 0 assignees View on GitHub
hints Java kind:bug
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 24 release candidate

### What happened

In the following code the first comment line gets deleted when CTRL+SHIFT+I is pressed to fix imports:

```
package com.mycompany.fiximportdeletescommentdemo;

import java.util.List;

// https://github.com/toby1984/swing-autocomplete
// xxx
// https://github.com/toby1984/swing-autocomplete/blob/master/src/test/java/de/codesourcery/swing/autocomplete/Demo.java
public class FixImportDeletesCommentDemo {

public static void main(String[] args) {
System.out.println("Hello World!");
}
}
```

I could reproduce this behaviour with NetBeans 22 and NetBeans 24-rc3. It only occurs if all imports are about to be removed and the code does not contain any unresolved imports. If those criterias are met the issue is always reproduceable.

A trivial Maven project to demonstrate this issue: [FixImportDeletesCommentDemo.zip](https://github.com/user-attachments/files/17748376/FixImportDeletesCommentDemo.zip)

### Language / Project Type / NetBeans Component

Java editor

### How to reproduce

See text above and attached project.

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Linux Mint 21.3 Cinnamon

### JDK

17.0.12; OpenJDK 64-Bit Server VM 17.0.12+7-Ubuntu-1ubuntu222.04

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

_No response_

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Start with the Java editor's Fix Imports action, reproduced with CTRL+SHIFT+I, and use the attached FixImportDeletesCommentDemo Maven project. Verify the case where all imports are removed and no unresolved imports exist; done means the first comment line and the remaining comments are preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.