Skip to content

Tools > Editor > OnSave > Java > RemoveUnusedImports sometimes ignored #9514

Description

@errael

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<Object> l1;
    LinkedList<Object> 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 #202605191504177946462222.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugBug report or fixneeds:triageRequires attention from one of the committers

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions