Bug 560439 - "Organize Imports" adds unnecessary static import when creating anonymous class of enclosing interface and calling static method within
Summary: "Organize Imports" adds unnecessary static import when creating anonymous cla...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.14   Edit
Hardware: PC Windows 10
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-23 11:33 EST by Some User CLA
Modified: 2024-02-04 15:39 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Some User CLA 2020-02-23 11:33:57 EST
It appears "Source" > "Organize Imports" adds unnecessary static imports for interfaces when an anonymous class of the interface is created and within it a static method of the interface is called:

```
package test;

// Apparently only happens for interfaces, but not for classes
interface StaticImportTest {
    static void use(String s) { }
    
    default void test(String s) {
        // Must be anonymous class of enclosing interface
        new StaticImportTest() {
            { 
                use(""); // <-- Static import is added for this
            }
        };
    }
}
```

However, since the method is declared in the same enclosing interface a warning is shown for the static import because it is not used:
```
// The import test.StaticImportTest.use is never used
import static test.StaticImportTest.use;
```

Especially when "Organize Imports" is set as "Save Action" this can become annoying.
Comment 1 Eclipse Genie CLA 2022-02-13 03:33:35 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Eclipse Genie CLA 2024-02-04 15:39:35 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.