apache / apache/netbeans

Tools > Editor > OnSave > Java > RemoveUnusedImports sometimes ignored

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

Description

### Apache NetBeans version

Apache NetBeans 31 latest release candidate

### What happened

At `Tools > Editor > OnSave > Java`
- Uncheck `Remove unused Imports`
- Check `Organize Imports`
- Apply
- Save the following (note ArrayList is commented out)

Observe
`import java.util.ArrayList;` is removed even though `Remove Unused Imports` is unchecked.
```
package com.raelity.play;

import java.util.ArrayList;
import java.util.LinkedList;

public class DontRemoveUnusedImportOnSave
{
// ArrayList l1;
LinkedList l2;
}
```

### Language / Project Type / NetBeans Component

java/OnSave (hints?/options?)

### How to reproduce

See OP.

If this behavior is what's wanted (it's not what I want), then in the UI when `Organize Imports` is checked, `Remove Unused Imports` should be both checked and disabled automatically.

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

No / Don't know

### Operating System

Linux harmony 7.0.9-76070009-generic #202605191504~1779464622~22.04~ef31795 SMP PREEMPT_DYNAMIC Fri M x86_64 x86_64 x86_64 GNU/Linux

### JDK

openjdk 26 2026-03-17 OpenJDK Runtime Environment (build 26+35-2893) OpenJDK 64-Bit Server VM (build 26+35-2893, mixed mode, sharing)

### 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 by reproducing the issue through Tools > Editor > OnSave > Java with Remove unused Imports unchecked and Organize Imports checked, then save the provided Java example. Trace the OnSave handling for these two settings and verify that disabling Remove unused Imports prevents ArrayList from being removed, or that the UI clearly enforces the dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.