Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 526366

Summary: Necessary annotation import marked as unused
Product: [Eclipse Project] JDT Reporter: Aaron Digulla <digulla>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P3    
Version: 4.7.1a   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Aaron Digulla CLA 2017-10-23 10:06:30 EDT
I just copied org.eclipse.jdt.annotation.NonNull into my project because I needed to change @Retention to RUNTIME.

These five lines are marked as unused imports:

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

even though the annotations are in fact used later:

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ TYPE_USE })
public @interface NonNull {
    // marker annotation with no members
}

My guess is that the compiler just checks for classes below the "java.lang" package without taking into account subpackages ("java.lang.annotation") which need an explicit import.

Note: Probably a duplicate but I couldn't find it.
Comment 1 Eclipse Genie CLA 2020-01-18 16:44:22 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.