Bug 420045 - [1.8][compiler] Pull back temporary bug compatibility mode with javac (AnnotatedConstruct#getAnnotationMirrors() etc.))
Summary: [1.8][compiler] Pull back temporary bug compatibility mode with javac (Annota...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 422337 (view as bug list)
Depends on:
Blocks: 429559 564617
  Show dependency tree
 
Reported: 2013-10-22 03:47 EDT by Srikanth Sankaran CLA
Modified: 2022-07-31 16:59 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2013-10-22 03:47:31 EDT
BETA_JAVA8: 

As of 8b111, there are a few areas where ECJ and javac differ in that either
javac has a clear bug or has not implemented some part of the spec.

This CR is to make eclipse mimic javac behavior to the extent possible without
introducing bugs that would affect program behavior:

At the moment, there are 3 items:

1. '_' as an identifier triggers a warning in javac, an error in eclipse.
2. Annotations are tolerated on dimensions of a class literal expression
such as int @T [].class.
3. javac does not yet diagnose the illegal scenario of a repeatable annotation
being used along with repeating container.

I propose to make all of these warnings at the moment, leave this CR open and
revert the right behavior before GA. This is so as to minimize surprises. Since
in each case, we warn clearly and since these areas are chosen carefully as
ones not affecting run time behavior, we are good.

As we discover more such areas, we should update the list and republish the
full list as a comment, so up to date issues list can be found by reading
the latest comment rather than having to scan through.
Comment 1 Srikanth Sankaran CLA 2013-10-22 04:06:54 EDT
For the set of cases identified in comment#0: here is the patch that makes
them warnings instead of errors: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=b31cd8ccd51413655d3e805905e8dd7d1404f391
Comment 2 Srikanth Sankaran CLA 2013-10-22 04:08:09 EDT
Will tag this item as blocking bug 380190, since these behaviors must be
reverted before the release.
Comment 3 Srikanth Sankaran CLA 2013-11-14 05:17:41 EST
(In reply to Srikanth Sankaran from comment #0)

> 1. '_' as an identifier triggers a warning in javac, an error in eclipse.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=421711. We are in compliance
with the spec now as well as javac.
Comment 4 Srikanth Sankaran CLA 2013-11-22 08:53:27 EST
*** Bug 422337 has been marked as a duplicate of this bug. ***
Comment 5 Srikanth Sankaran CLA 2014-03-05 01:33:53 EST
In http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=712689471fd4116d08552bca059239228ce897f6 I made annotations
on class literals an error again.
Comment 6 Srikanth Sankaran CLA 2014-03-05 01:38:09 EST
We have only one at the moment.

We emit a warning when the container and the containee are present on the
same element. Javac is silent. It should be an error.
Comment 7 Srikanth Sankaran CLA 2014-03-05 02:43:48 EST
In commit http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=4207a2afae6c22729e09d7310b464a6d241a4a46

I am injecting a bug to match javac bug https://bugs.openjdk.java.net/browse/JDK-8031744.

This will have to pulled back at a suitable point and the disabled test
Java8ElementsTests.testTypeAnnotations27 needs to be reenabled.

Javac 8b129 is failing this test while eclipse is passing.

An preference has been introduced to control the behavior: 

org.eclipse.jdt.core.compiler.emulateJavacBug8031744 (enabled/disabled)
Comment 8 Srikanth Sankaran CLA 2014-11-02 23:19:24 EST
Jay, at some point we should check if javac behavior has changed and
eliminate the bugs we injected to be compatible. I didn't check the
present status.
Comment 9 Jay Arthanareeswaran CLA 2014-11-07 01:48:28 EST
(In reply to Srikanth Sankaran from comment #8)
> Jay, at some point we should check if javac behavior has changed and
> eliminate the bugs we injected to be compatible. I didn't check the
> present status.

As of jdk-8u25, the status hasn't changed
Comment 10 Jay Arthanareeswaran CLA 2015-02-03 04:22:01 EST
No change as of jdk-8u31. For future reference, here's the test case:

import java.lang.annotation.Inherited;
import java.lang.annotation.Repeatable;

@IFooContainer({@IFoo(1), @IFoo(2)}) @IFoo(1)
public class X {}

@Repeatable(IFooContainer.class)
@Inherited
@interface IFoo {
	int value() default -1;
}
@Inherited
@interface IFooContainer {
	IFoo [] value();
}
Comment 11 Stephan Herrmann CLA 2015-02-03 05:56:47 EST
(In reply to Jay Arthanareeswaran from comment #10)
> No change as of jdk-8u31. For future reference, here's the test case:
> 
> import java.lang.annotation.Inherited;
> import java.lang.annotation.Repeatable;
> 
> @IFooContainer({@IFoo(1), @IFoo(2)}) @IFoo(1)
> public class X {}
> 
> @Repeatable(IFooContainer.class)
> @Inherited
> @interface IFoo {
> 	int value() default -1;
> }
> @Inherited
> @interface IFooContainer {
> 	IFoo [] value();
> }

Just to be sure, we're on the same page: we are waiting for javac to report an error, right?

Also javac 1.8.0_40-ea is silent.
Comment 12 Jay Arthanareeswaran CLA 2015-02-03 08:00:45 EST
(In reply to Stephan Herrmann from comment #11)
> Just to be sure, we're on the same page: we are waiting for javac to report
> an error, right?

Yes.
Comment 13 Jay Arthanareeswaran CLA 2015-04-20 02:07:15 EDT
As of jdk-8u45, status quo remains.

I wonder if there are plans to address these in the Oracle compiler. For now moving out of Mars.
Comment 14 Jay Arthanareeswaran CLA 2016-04-05 04:09:42 EDT
Javac continues to be quiet wrt as of 8u72. Moving out of 4.6.
Comment 15 Markus Keller CLA 2016-04-20 12:22:37 EDT
(In reply to Jay Arthanareeswaran from comment #12)
> (In reply to Stephan Herrmann from comment #11)
> > Just to be sure, we're on the same page: we are waiting for javac to report
> > an error, right?
> 
> Yes.

You may be on the same page, but that doesn't make it the right page ;-)

The example in comment 10 is valid Java 8 code. JLS 8 9.7.5 only says: "It is a compile-time error if, in a declaration context or type context, there are
multiple annotations of a repeatable annotation type T and any annotations of the
containing annotation type of T."

Later on, there's an example of a valid use of a single repeatable annotation next to an explicit annotation of the container type:

@Foo(1) @FooContainer({@Foo(2)})
class A {}

This is structurally equivalent to comment 10.
Comment 16 Jay Arthanareeswaran CLA 2016-04-20 12:59:58 EDT
(In reply to Markus Keller from comment #15)
  You are right, thanks for digging it out.

My bad, I just went along with the comments and didn't bother to check the spec. Or perhaps the spec changed along the course that I failed to notice.

In any case, we have nothing more to do for this case.
Comment 17 Markus Keller CLA 2016-04-20 13:06:57 EDT
(In reply to Srikanth Sankaran from comment #0)
> 3. javac does not yet diagnose the illegal scenario of a repeatable
> annotation
> being used along with repeating container.

(In reply to Srikanth Sankaran from comment #6)
> We have only one at the moment.
> 
> We emit a warning when the container and the containee are present on the
> same element. Javac is silent. It should be an error.

I think Srikanth misread the spec previews, which already allowed such combinations as long as neither the repeatable annotation nor the container annotation are repeated.

=> All problems from comment 0 seem to be resolved by now.


Comment 7 is a new problem, but that's not about the compiler, but about APT's reflective API javax.lang.model.AnnotatedConstruct#getAnnotationMirrors(), which still seems to be broken up to jdk 9-ea+110

See CompilerOptions.emulateJavacBug8031744 and the commit in comment 7.
Comment 18 Jay Arthanareeswaran CLA 2017-08-16 17:55:35 EDT
Annotations on dimensions of a class literal expression are reported by Java9 build 179. Item (2) from comment #0 can now be fixed.
Comment 19 Eclipse Genie CLA 2017-08-16 19:21:31 EDT
New Gerrit change created: https://git.eclipse.org/r/103203
Comment 21 Eclipse Genie CLA 2017-09-01 06:00:27 EDT
New Gerrit change created: https://git.eclipse.org/r/104149
Comment 23 Manoj N Palat CLA 2018-05-21 06:11:39 EDT
@Jay: Are there any pending items in this? If not please move it to resolved
Comment 24 Manoj N Palat CLA 2018-05-21 06:13:49 EDT
Bulk move out of 4.8
Comment 25 Eclipse Genie CLA 2022-07-31 16:59:46 EDT
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.