Bug 456960 - Broken classfile generated for incorrect annotation usage - case 2
Summary: Broken classfile generated for incorrect annotation usage - case 2
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 4.5 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 455608
  Show dependency tree
 
Reported: 2015-01-07 14:18 EST by Andrew Clement CLA
Modified: 2015-03-18 05:07 EDT (History)
5 users (show)

See Also:
sasikanth.bharadwaj: review+


Attachments
Proposed patch including a regression test (3.44 KB, patch)
2015-01-08 10:47 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Clement CLA 2015-01-07 14:18:30 EST
This is another variant of bug 434556. Testcode:

===
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Bar(String)
public class Code2 {
 
}

@Retention(RetentionPolicy.RUNTIME)
@interface Bar {
	Class<?>[] value();
}

===

If the annotation is correctly specified as '@Bar(String.class)' then the generated classfile is valid. If just @Bar(String) is used we get an error as expected but the generated class file has an invalid attribute for the annotation. Javap cannot understand it so just prints the bytes:

    RuntimeVisibleAnnotations: length = 0xA
     00 01 00 16 00 01 00 17 00 00 

00 01 = there is one annotation
00 16 = the nameindex for the annotation is 0x16: 'LBar;'
00 01 = the annotation has one name value pair
00 17 = the name of the name value pair is at index 0x17: 'value'
00 00 = ????? it should be one byte for the type of the annotation value and then a pair for the annotation value index.

This appears to be due to the handling in ClassFile.generateAnnotation() as with that other bug. That fix only got applied to the case of an annotation with multiple values, this time we have an annotation with only one value which is treated differently (as a SingleMemberAnnotation rather than a NormalAnnotation). Similar logic to what was used in the NormalAnnotation case under that bug fix needs applying here. We should be not including the invalid member value. From a cursory look it *might* be slightly different here as the 'if (this.contentsOffset == memberValuePairOffset)' may be triggering.
Comment 1 Jay Arthanareeswaran CLA 2015-01-07 23:57:19 EST
Thanks for the report and analysis, Andrew. 

Sasi, please take a look.
Comment 2 Olivier Thomann CLA 2015-01-08 10:29:16 EST
Jay, I can take care of this one as I did the fix that is mentioned in comment 0.
Comment 3 Olivier Thomann CLA 2015-01-08 10:44:08 EST
Right now the code tries to remove just the annotation's value as it is invalid. As this seems to cause problem, the best solution is to remove the annotation all together.
Fix to follow.
Comment 4 Olivier Thomann CLA 2015-01-08 10:47:14 EST
Created attachment 249792 [details]
Proposed patch including a regression test
Comment 5 Jay Arthanareeswaran CLA 2015-01-08 23:17:32 EST
Thanks for the patch, Olivier!

Sasi, please review and release this patch.
Comment 6 Jay Arthanareeswaran CLA 2015-01-29 00:02:18 EST
Sasi, this one slipped through. Please take this up once M5 is out.
Comment 7 Sasikanth Bharadwaj CLA 2015-02-04 04:07:44 EST
Patch looks good to me. All tests pass with the patch. Released via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=51d45c360e379dc3d174cfefd6624f6613e9055b
Comment 8 Manoj N Palat CLA 2015-03-18 05:07:18 EDT
Verified for Eclipse Mars 4.5 M6 Build id: I20150317-2000