You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The very 1st import in a new class without package declaration is added above the copyright header #9661
The very 1st and subsequent imports are being added above the copyright header, when acting upon the Alt-Enter drop-down.
If however at least 1 import exists beneath the copyright header, then the subsequent imports trail it.
Language / Project Type / NetBeans Component
Java
How to reproduce
Create a new Java class. Add some code that requires imports. Alt-Enter the lines and add imports.
probably in default packages when the package declaration is missing. The import would land above the comment since there is nothing to anchor on. If the first import is manually adjusted its position will be used as reference.
changed the title [-]The very 1st import in a new class is added above the copyright header[/-][+]The very 1st import in a new class without package declaration is added above the copyright header[/+]on Oct 6, 2026
Meanwhile I dug into this a bit and found the actual cause.
There is a method in the comment handling code that deliberately skips attaching the copyright header to the file when there is no package declaration. That is why the header ends up attached to the class instead, and a new import gets placed above it rather than below.
This code is old, it goes back to the original donation to Apache in 2017, and it is shared by a lot of Java source generation features, not just imports. So I want to be careful rather than changing it directly.
I am thinking of fixing this on the import insertion side instead, making sure a new import always lands after any leading header comment, rather than touching the shared comment logic itself.
Activity
dca00 commentedon Oct 4, 2026
I just dragged a class from the default package to another, and the refactor added the package also above the copyright header.
mbien commentedon Oct 6, 2026
probably in default packages when the package declaration is missing. The import would land above the comment since there is nothing to anchor on. If the first import is manually adjusted its position will be used as reference.
reproducer.
going to rename the title to be more precise.
[-]The very 1st import in a new class is added above the copyright header[/-][+]The very 1st import in a new class without package declaration is added above the copyright header[/+]ashwintemkar commentedon Oct 8, 2026
Interesting issue. I would like to open a draft PR for this, it looks simple at first glance.
ashwintemkar commentedon Oct 8, 2026
Meanwhile I dug into this a bit and found the actual cause.
There is a method in the comment handling code that deliberately skips attaching the copyright header to the file when there is no package declaration. That is why the header ends up attached to the class instead, and a new import gets placed above it rather than below.
This code is old, it goes back to the original donation to Apache in 2017, and it is shared by a lot of Java source generation features, not just imports. So I want to be careful rather than changing it directly.
I am thinking of fixing this on the import insertion side instead, making sure a new import always lands after any leading header comment, rather than touching the shared comment logic itself.
Does that sound okay to move forward with?