Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested records have unneeded import #232

Open
frankbenoit opened this issue Jul 16, 2022 · 6 comments
Open

Nested records have unneeded import #232

frankbenoit opened this issue Jul 16, 2022 · 6 comments
Assignees

Comments

@frankbenoit
Copy link

Version: 2022-06 (4.24.0)
Build id: 20220609-1112

Given a record nesting a record:

record A( int v, B b ){
    record B( String n ){}
}

On organize imports, this will have an import for B. At the same time this import is marked as unneeded.

@nlisker
Copy link

nlisker commented Jul 17, 2022

The bug occurs for any nested type, not just if B is a record. Try enum and class too.

@pme-sap
Copy link

pme-sap commented Dec 7, 2022

Retested with 2022-09 and 2022-12 as well (Version: 2022-12 (4.26.0) - Build id: 20221201-1913).

The issue is still there. To reproduce:

  1. Import attached project EclipseBug-579273.zip
  2. See the warning "unused import" on Rec.java:3
  3. Manually delete line 3 & save
  4. Execute Source -> Organize Imports and find the unused import again

@jarthana
Copy link
Member

I can reproduce this with latest Eclipse build. Looks like the issue is in ImportRewrite (in jdt.ui) that doesn't check for the names from inner types. This made sense for types because we won't encounter inner types names as part of the outer type's declaration. But as seen in this example, records are an exception.

One way to fix this would be, in ImportRewrite#findInImports(), we should look for known names from body declarations of a record and if found return ImportRewriteContext.RES_NAME_FOUND

Could be a good first for a beginner.

Tag @noopur2507

@pme-sap
Copy link

pme-sap commented Mar 15, 2023

Still present in 2023-03 (4.27.0) - Build id: 20230309-1520

@jarthana
Copy link
Member

@noopur2507 Can you please take this forward?

@arithauth
Copy link

I met it on May 6, 2023 and found this opened issue.
Language Support for Java(TM) by Red Hat v1.18.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants