Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 390882 - [1.8][compiler] Compiler should reject type annotations on nested package names and qualified top level types
Summary: [1.8][compiler] Compiler should reject type annotations on nested package nam...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: BETA J8   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 287648
  Show dependency tree
 
Reported: 2012-10-01 22:09 EDT by Srikanth Sankaran CLA
Modified: 2012-10-05 12:03 EDT (History)
0 users

See Also:
srikanth_sankaran: review+


Attachments
Proposed fix (2.93 KB, patch)
2012-10-02 12:20 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Updated patch (3.80 KB, patch)
2012-10-03 09:58 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Same fix with more tests (5.17 KB, patch)
2012-10-05 01:52 EDT, Jay Arthanareeswaran CLA
no flags Details | Diff
Updated patch (8.10 KB, patch)
2012-10-05 05:41 EDT, Jay Arthanareeswaran CLA
jarthana: review?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2012-10-01 22:09:05 EDT
BETA_JAVA8:

This program compiles without any errors when built against 308 enabled
8b56:

// -----------
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;

public class X {
    Object o1 = (@Marker java.lang.Integer) null;   // 1. Right.
    Object o2 = (java. @Marker lang.Integer) null;  // 2. Wrong.
    Object o3 = (java.lang. @Marker Integer) null;  // 3. Wrong.
}

@Target(TYPE_USE)
@interface Marker {
	
}
// ----------------------------------

2 is annotating a nested package name - 308 does not allow this.
3 is annotating a top level type - the proper way to this is to
use 1 style prefix annotations.

Note that 8b50 javac crashes on this test case.
Comment 1 Srikanth Sankaran CLA 2012-10-01 22:09:35 EDT
Jay, please take a look.
Comment 2 Jay Arthanareeswaran CLA 2012-10-02 12:20:17 EDT
Created attachment 221787 [details]
Proposed fix

Fix + test for the test case in comment #0. The tests probably adjusted for the time being so that it will pass with a JDK without JSR 308 support.
Comment 3 Jay Arthanareeswaran CLA 2012-10-03 09:58:38 EDT
Created attachment 221834 [details]
Updated patch

Some minor changes to the previous patch. Test has been updated as well.
Comment 4 Srikanth Sankaran CLA 2012-10-03 11:15:54 EDT
Patch looks good. I recommend that you add two more tests: (a) one with more
than one illegal annotation to make sure the source range reported is
correct (b) another with just a package name like @Marker java.@lang lang.

Just looking at the code, I expected to see an AIOOB for (b), but it is
handled well before package binding comes out as null - anyways a test 
is welcome - it will be missing the new errors, but that is probably ok
as it will be a secondary error.
Comment 5 Srikanth Sankaran CLA 2012-10-04 00:48:00 EDT
I think the patch is good - but we should consider emitting more 
specific messages than syntax errors. It can be argued these are
not syntax errors at all. Jay, what do you think ?
Comment 6 Jay Arthanareeswaran CLA 2012-10-04 01:40:19 EDT
(In reply to comment #5)
> I think the patch is good - but we should consider emitting more 
> specific messages than syntax errors. It can be argued these are
> not syntax errors at all. Jay, what do you think ?

Yes, it can be argued. However, I think the spec only talks about type qualifier and not qualifiers in general. In that sense, we can call it a syntax error also, can't we?
Comment 7 Jay Arthanareeswaran CLA 2012-10-05 01:52:43 EDT
Created attachment 221938 [details]
Same fix with more tests

Patch is same as previous, but includes the two new tests Srikanth suggested. Note that I intend to release with the tests disabled until we get a JDK with both 308 and Lambda support.
Comment 8 Srikanth Sankaran CLA 2012-10-05 02:08:08 EDT
(In reply to comment #7)

> suggested. Note that I intend to release with the tests disabled until we
> get a JDK with both 308 and Lambda support.

Please update the list at bug 383608 - we want one list of all disabled
tests (i.e not scattered across multiple comments that would need to be 
scanned) - TIA.
Comment 9 Srikanth Sankaran CLA 2012-10-05 02:09:40 EDT
Please also fold the entry at https://bugs.eclipse.org/bugs/show_bug.cgi?id=383608#c5 into the master list currently at https://bugs.eclipse.org/bugs/show_bug.cgi?id=383608#c6. Thanks.
Comment 10 Jay Arthanareeswaran CLA 2012-10-05 04:35:41 EDT
The latest patch fails for qualified generic type references and array of qualified types. Here is the new list of tests including the one mentioned in comment #4.

Object o1 = (@Marker java.lang.Integer) null;   	// 1. Right.
Object o2 = (java. @Marker lang.Integer) null;  	// 2. Wrong.
Object o3 = (java.@Marker lang) null;  			// 3. Wrong.
Object o4 = (java.util.@Marker List<String>) null; 	// 4. Wrong.
Object o5 = (java.lang.@Marker Integer[]) null;		// 5. Wrong.
Object o6 = (java.util.@Marker List<String>[]) null;	// 6. Wrong.
Object o7 = (java.lang.Integer @Marker []) null;	// 7. Right.

I will post an updated patch to handle the new cases.(In reply to comment #8)


> (In reply to comment #7)
> Please update the list at bug 383608 - we want one list of all disabled
> tests (i.e not scattered across multiple comments that would need to be 
> scanned) - TIA.

Sure, I was planning to do that after I release the change. At this point, we are still looking at adding more tests.
Comment 11 Srikanth Sankaran CLA 2012-10-05 04:41:12 EDT
(In reply to comment #10)
> The latest patch fails for qualified generic type references and array of
> qualified types. Here is the new list of tests including the one mentioned
> in comment #4.

Please also tweak these tests, so there is an error reported for annotating
at the inner package level.

i.e 

   java.@Marker util.@Marker List<String>
Comment 12 Jay Arthanareeswaran CLA 2012-10-05 05:41:34 EDT
Created attachment 221943 [details]
Updated patch

This patch addresses the test cases that were failing later.

I thought I should make the other sub classes (SelectionOnQualifiedTypeReference and such) to use the new code to report the problems. But looks like the selection parser doesn't (yet) care about type annotations - the annotations instance variable is null.

Srikanth, should we file a new bug to make the selection parser to include the annotations?
Comment 13 Srikanth Sankaran CLA 2012-10-05 06:54:36 EDT
(In reply to comment #12)

> Srikanth, should we file a new bug to make the selection parser to include
> the annotations?

Done: bug 391214.
Comment 14 Srikanth Sankaran CLA 2012-10-05 07:38:17 EDT
Patch looks good. Two small suggestions: reportAnnotationsOnPackageQualifiers
is better named rejectAnnotationsOnPackageQualifiers (2) Please eliminate the second diff in both ParameterizedQualifiedTypeReference and QualifiedTypeReference. It needlessly leaks the variable i to outside the
for loop and is not relevant to the fix any more

It is enough to run just RunAllJava8Tests with these changes and release it.
Comment 15 Jay Arthanareeswaran CLA 2012-10-05 10:12:12 EDT
Released the fix in BETA_JAVA8
Comment 17 Srikanth Sankaran CLA 2012-10-05 11:07:18 EDT
(In reply to comment #14)
> (2) Please eliminate
> the second diff in both ParameterizedQualifiedTypeReference and
> QualifiedTypeReference. It needlessly leaks the variable i to outside the
> for loop and is not relevant to the fix any more

Only one of these seem to fixed. In QualifiedTypeReference, the variable is
still leaking outside of the for loop :-(
Comment 18 Jay Arthanareeswaran CLA 2012-10-05 12:03:23 EDT
(In reply to comment #17)
> Only one of these seem to fixed. In QualifiedTypeReference, the variable is
> still leaking outside of the for loop :-(

Oops, looks like I amended the commit with some changes still unstaged :(  I have fixed it now.