View | Details | Raw Unified | Return to bug 456960
Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (+58 lines)
Lines 11297-11300 Link Here
11297
	this.runConformTest(testFiles, "");
11297
	this.runConformTest(testFiles, "");
11298
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p/package-info.class", "", "HELLO");
11298
	checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p/package-info.class", "", "HELLO");
11299
}
11299
}
11300
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=456960
11301
public void test456960() throws Exception {
11302
	if (this.complianceLevel < ClassFileConstants.JDK1_5) {
11303
		return;
11304
	}
11305
	Map options = getCompilerOptions();
11306
	options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
11307
	options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
11308
	options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
11309
	this.runNegativeTest(
11310
		new String[] {
11311
			"X.java",
11312
			"@Bar(String)\n" + 
11313
			"public class X {\n" +
11314
			"}",
11315
			"Bar.java",
11316
			"import java.lang.annotation.Retention;\n" + 
11317
			"import java.lang.annotation.RetentionPolicy;\n" + 
11318
			"@Retention(RetentionPolicy.RUNTIME)\n" + 
11319
			"@interface Bar {\n" + 
11320
			"	Class<?>[] value();\n" + 
11321
			"}"
11322
		},
11323
		"----------\n" + 
11324
		"1. ERROR in X.java (at line 1)\n" + 
11325
		"	@Bar(String)\n" + 
11326
		"	     ^^^^^^\n" + 
11327
		"String cannot be resolved to a variable\n" + 
11328
		"----------\n",
11329
		null,
11330
		true,
11331
		null,
11332
		true, // generate output
11333
		false,
11334
		false);
11335
11336
	String expectedOutput =
11337
			"public class X {\n" + 
11338
			"  \n" + 
11339
			"  // Method descriptor #6 ()V\n" + 
11340
			"  // Stack: 3, Locals: 1\n" + 
11341
			"  public X();\n" + 
11342
			"     0  new java.lang.Error [8]\n" + 
11343
			"     3  dup\n" + 
11344
			"     4  ldc <String \"Unresolved compilation problem: \\n\\tString cannot be resolved to a variable\\n\"> [10]\n" + 
11345
			"     6  invokespecial java.lang.Error(java.lang.String) [12]\n" + 
11346
			"     9  athrow\n" + 
11347
			"      Line numbers:\n" + 
11348
			"        [pc: 0, line: 1]\n" + 
11349
			"      Local variable table:\n" + 
11350
			"        [pc: 0, pc: 10] local: this index: 0 type: X\n" + 
11351
			"}";
11352
	try {
11353
		checkDisassembledClassFile(OUTPUT_DIR + File.separator  +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.DETAILED);
11354
	} catch(org.eclipse.jdt.core.util.ClassFormatException cfe) {
11355
		fail("Error reading classfile");
11356
	}
11357
}
11300
}
11358
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java (-3 / +2 lines)
Lines 2390-2398 Link Here
2390
				try {
2390
				try {
2391
					generateElementValue(singleMemberAnnotation.memberValue, methodBinding.returnType, memberValuePairOffset);
2391
					generateElementValue(singleMemberAnnotation.memberValue, methodBinding.returnType, memberValuePairOffset);
2392
					if (this.contentsOffset == memberValuePairOffset) {
2392
					if (this.contentsOffset == memberValuePairOffset) {
2393
						// ignore annotation value
2393
						// completely remove the annotation as its value is invalid
2394
						this.contents[this.contentsOffset++] = 0;
2394
						this.contentsOffset = startingContentsOffset;
2395
						this.contents[this.contentsOffset++] = 0;
2396
					}
2395
					}
2397
				} catch(ClassCastException e) {
2396
				} catch(ClassCastException e) {
2398
					this.contentsOffset = startingContentsOffset;
2397
					this.contentsOffset = startingContentsOffset;

Return to bug 456960