Bug 95056 - [1.5][compiler] @Deprecated not recognized
Summary: [1.5][compiler] @Deprecated not recognized
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 98088 124119 124148 124301 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-05-12 18:03 EDT by Philipe Mulet CLA
Modified: 2006-02-15 05:12 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2005-05-12 18:03:56 EDT
Build 20050509

In some situations when 2 source files are compiled at once, a @Deprecated
annotation isn't resolved soon enough for it to be used appropriately.

Test case: compile simultaneously

// X.java
public class X extends p.OldStuff {
} 

// p/OldStuff.java
package p;
@Deprecated
public class OldStuff {
}

If X gets compiled before OldStuff, then the latter only gets requested as a
supertype, and didn't yet fault-in its method/field which are triggering the
annotation resolution (to find out it is deprecated).

See senders of SourceTypeBinding#getAnnotationTagBits().
The difficulty is that when annotations are resolved, it may refer to many other
types, and should be done once reasonable state got achieved. 

Added AnnotationTest#test143.

Other case is ReconcileTests#testSuppressWarning1 where the /** @deprecated */
is replaced with @Deprecated.
Comment 1 Philipe Mulet CLA 2005-05-13 04:42:48 EDT
Made ReconcilerTest#testSuppressWarning1 use @Deprecated, and turned it off for
now. It is exhibiting a slightly different code path than AnnotationTest#test143.

Inclination would be to resolve portions of type annotations right after type
hierarchy if possible... values may require field constants or methods, but the
type reference shouldn't.
@MyAnnotation(....)
  ^^^^
   this portion could be resolved earlier
Comment 2 Olivier Thomann CLA 2005-06-02 13:05:03 EDT
*** Bug 98088 has been marked as a duplicate of this bug. ***
Comment 3 Philipe Mulet CLA 2005-06-13 06:34:34 EDT
Dani - would you vote to fix this for RC3 ?
Comment 4 Dani Megert CLA 2005-06-13 06:40:55 EDT
+1
Comment 5 Philipe Mulet CLA 2005-06-13 06:45:31 EDT
+1 for RC3
Comment 6 Kent Johnson CLA 2005-06-15 14:08:17 EDT
We cannot resolve the Deprecated annotation 'normally' until the imports have 
been faulted in, which happens in CompilationUnitScope.faultInTypes()... 
called from Compiler.process().

What's special about the Deprecated annotation?

If it just looks like @Deprecated, then why can we not pick it up in parser? 
Or do a special walk over a type's annotations to see if it exists?
Comment 7 Philipe Mulet CLA 2005-06-15 14:17:22 EDT
I can define my own @interface Deprecated which would hide the one from java.lang.
Comment 8 Kent Johnson CLA 2005-06-16 10:30:57 EDT
I have tried adding an extra step between imports & hierarchy resolution, but 
its causing a ton of errors trying to resolve fields/methods in some 
annotations.

Unlikely we'll have a fix for this one.
Comment 9 Frederic Fusier CLA 2006-01-10 13:28:48 EST
Another symptom of this problem is shown by following test case:
p2/I.java
  package p2;
  /** @deprecated */
  interface I {}

p1/X.java
  package p1;
  public class X {
	@Deprecated
	class Y implements p2.I {}
  }

I expected not to have any warning but got one in X.java saying that p2.I is deprecated...

Note that replacing @Deprecated annotation by /** @deprecated */ javadoc tag fixes the problem:
p2/I.java
  /** @deprecated */
  interface I {}

p1/X.java
  package p1;
  public class X {
	/** deprecated */
	class Y implements p2.I {}
  }
Comment 10 Philipe Mulet CLA 2006-01-18 11:56:12 EST
Original problem came from unresolved annotation at the time the check is performed. Interestingly, a change made for bug 76266 did trigger resolution of the annotations, and thus address this bug in appearance.

Now, it also caused regressions such as bug 124119.

Implemented instead fix for bug 124148, and ensures the introduced API is invoked in ASTNode#isTypeUseDeprecated(...).

Enabled AnnotationTest#test143
Comment 11 Philipe Mulet CLA 2006-01-18 12:45:52 EST
*** Bug 124148 has been marked as a duplicate of this bug. ***
Comment 12 Philipe Mulet CLA 2006-01-18 12:47:30 EST
Frederic - pls check your scenario, and fork it into a separate bug if still reproduceable in HEAD.

Fixed
Comment 13 Philipe Mulet CLA 2006-01-18 12:49:05 EST
*** Bug 124119 has been marked as a duplicate of this bug. ***
Comment 14 Frederic Fusier CLA 2006-01-18 13:13:23 EST
*** Bug 124301 has been marked as a duplicate of this bug. ***
Comment 15 Philipe Mulet CLA 2006-01-18 13:22:56 EST
Also re-enabled ReconcilerTest#testSuppressWarning1 
Comment 16 Frederic Fusier CLA 2006-01-18 13:25:10 EST
Comment 9 sample is not fixed with HEAD contents => I'll open a new for this specific issue...
Comment 17 Frederic Fusier CLA 2006-01-18 13:42:37 EST
Open bug 124436 to address comment 9 issue...
Comment 18 Jerome Lanneluc CLA 2006-02-15 05:12:31 EST
Verified for 3.2 M5 using build I20060215-0010