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

Bug 399453

Summary: [1.8][compiler] Annotation preceding the first dimension in array creation expression is added to the type
Product: [Eclipse Project] JDT Reporter: Jay Arthanareeswaran <jarthana>
Component: CoreAssignee: Jay Arthanareeswaran <jarthana>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: srikanth_sankaran
Version: 3.8Flags: srikanth_sankaran: review+
Target Milestone: BETA J8   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 391894    
Attachments:
Description Flags
Proposed fix none

Description Jay Arthanareeswaran CLA 2013-01-29 23:27:39 EST
It should, instead, be added to the TypeReference#annotationsOnDimensions at index '0'.

Consider this code:
  new int @Marker [bar()] @Marker2 [] @Marker3 []

The parser attaches @Marker to the TypeReference#annotations and not to the ArrayAllocationExpression#annotationsOnDimensions. As a result the first element of the annotationsOnDimensions is always empty, even though the rest of the annotations seem to be attached at appropriate indexes.
Comment 1 Jay Arthanareeswaran CLA 2013-01-29 23:49:48 EST
At first glance, looks like the method invocation node bar() is inserting an empty annotation via consumeZeroTypeAnnotations(). Need to figure out what is the best way out.
Comment 2 Srikanth Sankaran CLA 2013-01-30 01:32:34 EST
The type annotation + length stacks are incorrect. We have a problem with
message sends.

See that this program is silently accepted by eclipse, while javac rejects it.

public class X {
 	public void foo() {
		int x = @Marker bar();  
	}
	public int bar() {
		return 2;
	}
}

Problem appears to be in consumeMethodInvocationName(). If you change the call
to X.bar() and change bar() to static things work ok.


The else {} blocks diagnoses misplaced annotations while if doesn't.

When you fix this, see if the variants of consumeMethodInvocationName also
need a fix and add suitable test cases, both good and bad.
Comment 3 Jay Arthanareeswaran CLA 2013-01-30 11:38:55 EST
Created attachment 226328 [details]
Proposed fix

Patch with regression tests.
Comment 4 Srikanth Sankaran CLA 2013-01-30 12:59:43 EST
Patch looks good. I would simply inline the new method rejectTypeAnnotationsOnMethodInvocation at the call site and get rid of it.
Thanks.
Comment 5 Jay Arthanareeswaran CLA 2013-01-30 23:39:50 EST
(In reply to comment #4)
> Patch looks good. I would simply inline the new method
> rejectTypeAnnotationsOnMethodInvocation at the call site and get rid of it.
> Thanks.

I have made this change and released the fix.