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

Bug 415543

Summary: [1.8][compiler] Incorrect bound index in RuntimeInvisibleTypeAnnotations attrribute
Product: [Eclipse Project] JDT Reporter: Srikanth Sankaran <srikanth_sankaran>
Component: CoreAssignee: Andrew Clement <aclement>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 4.4   
Target Milestone: BETA J8   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 409235    
Attachments:
Description Flags
Fix and test for bug none

Description Srikanth Sankaran CLA 2013-08-21 02:51:17 EDT
BETA_JAVA8:
----------

From the spec:

"When the annotation’s target is a bound of a type parameter of a class or 
method, target info contains one type parameter bound target: 

type_parameter_bound_target {
    u1 type_parameter_index;
    u1 bound_index;
};

type parameter index specifies the index of the type parameter, while bound 
index specifies the index of the bound. Indexes start at 0. Bound index 0 is
always a class, not interface, type. If the programmer-supplied upper bound 
of the type variable is an interface, it is treated as the second bound, and 
the implicit first bound is java.lang.Object.

// ---

Given that, given the following program:

// ---
import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*; 
@Target({TYPE_USE}) @interface NonNull { }

class X <T extends @NonNull Comparable> {
	
}
// --

we generate bad code:

"  RuntimeInvisibleTypeAnnotations: \n" + 
				"    #21 @NonNull(\n" + 
				"      target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + 
				"      type parameter index = 0 type parameter bound index = 0\n" + 
				"    )\n" + 
				"}"

javac 8b100 generates:

  RuntimeInvisibleTypeAnnotations:
    0: #13(): CLASS_TYPE_PARAMETER_BOUND, param_index=0, bound_index=1

which is correct.
Comment 1 Srikanth Sankaran CLA 2013-08-21 02:52:24 EDT
Andy, please follow up, TIA.

Regression test available via: org.eclipse.jdt.core.tests.compiler.regression.JSR308SpecSnippetTests.test034()
(which will have to be massaged).
Comment 2 Andrew Clement CLA 2013-08-21 19:38:15 EDT
Created attachment 234639 [details]
Fix and test for bug

I couldn't find the test you referenced (didn't seem to be in there) so I created one using the code embedded in the bug and I also added another that tested a few more variants and tested the method type parameter case.

Recommend applying patch for bug 415541 first (just to simplify merging)
Comment 3 Srikanth Sankaran CLA 2013-08-22 02:17:38 EDT
(In reply to comment #2)
> Created attachment 234639 [details]
> Fix and test for bug
> 
> I couldn't find the test you referenced (didn't seem to be in there) so I
> created one using the code embedded in the bug and I also added another that
> tested a few more variants and tested the method type parameter case.

Thanks, I had forgotten to release the test I had in my workspace. Sorry.

Patch looks good. Released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=7089fcfd703b096f125599a900905c00e15535fa
Comment 4 Andrew Clement CLA 2013-08-22 12:02:06 EDT
This contribution complies with http://www.eclipse.org/legal/CoO.php