Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Clement2013-08-22 05:30:00 +0000
committerssankaran2013-08-22 05:30:00 +0000
commit2f99f11ed182db13b52f83c7f61547c34d00226d (patch)
treeb488d1f502b21eeefcc907c87240324c97f99f9d
parent3e3b51c55228cb418d3e20ad2161182869812a5e (diff)
downloadeclipse.jdt.core-2f99f11ed182db13b52f83c7f61547c34d00226d.tar.gz
eclipse.jdt.core-2f99f11ed182db13b52f83c7f61547c34d00226d.tar.xz
eclipse.jdt.core-2f99f11ed182db13b52f83c7f61547c34d00226d.zip
Fixed Bug 415541 - [1.8][compiler] Type annotations in the body of
static initializer get dropped. Signed-off-by: Andrew Clement <aclement@gopivotal.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java52
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java9
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java11
3 files changed, 53 insertions, 19 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java
index 0297c857f0..98659b68ac 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java
@@ -11,7 +11,8 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- *
+ * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
+ * Bug 415541 - [1.8][compiler] Type annotations in the body of static initializer get dropped
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -1380,7 +1381,7 @@ public class JSR308SpecSnippetTests extends AbstractRegressionTest {
checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
}
// Test type annotations in initializer code.
- public void test033() throws Exception { // WILL NEED TO BE ADJUSTED ONCE https://bugs.eclipse.org/bugs/show_bug.cgi?id=415541 IS FIXED.
+ public void test033() throws Exception {
this.runConformTest(
new String[] {
"X.java",
@@ -1401,6 +1402,18 @@ public class JSR308SpecSnippetTests extends AbstractRegressionTest {
"}\n",
},
"");
+ // javac b100
+ // For the annotations in the static {...} the clinit has:
+ // RuntimeInvisibleTypeAnnotations:
+ // 0: #11(): CAST, offset=0, type_index=0
+ // 1: #11(): NEW, offset=0
+ // javac is skipping production of the cast so offset is 0. JDT is currently always producing the
+ // checkcast for an annotated cast so the offset is 7.
+
+ // For the annotations in the initializer {...} the constructors both have:
+ // RuntimeInvisibleTypeAnnotations:
+ // 0: #11(): NEW, offset=4
+
String expectedOutput =
"// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
"class X {\n" +
@@ -1417,10 +1430,10 @@ public class JSR308SpecSnippetTests extends AbstractRegressionTest {
" constant #10 utf8: \"<init>\"\n" +
" constant #11 utf8: \"LineNumberTable\"\n" +
" constant #12 utf8: \"LocalVariableTable\"\n" +
- " constant #13 utf8: \"this\"\n" +
- " constant #14 utf8: \"LX;\"\n" +
- " constant #15 utf8: \"RuntimeInvisibleTypeAnnotations\"\n" +
- " constant #16 utf8: \"LNonNull;\"\n" +
+ " constant #13 utf8: \"RuntimeInvisibleTypeAnnotations\"\n" +
+ " constant #14 utf8: \"LNonNull;\"\n" +
+ " constant #15 utf8: \"this\"\n" +
+ " constant #16 utf8: \"LX;\"\n" +
" constant #17 utf8: \"(I)V\"\n" +
" constant #18 utf8: \"x\"\n" +
" constant #19 utf8: \"I\"\n" +
@@ -1430,14 +1443,25 @@ public class JSR308SpecSnippetTests extends AbstractRegressionTest {
" // Method descriptor #6 ()V\n" +
" // Stack: 2, Locals: 1\n" +
" static {};\n" +
- " 0 new java.lang.Object [3]\n" +
- " 3 dup\n" +
- " 4 invokespecial java.lang.Object() [8]\n" +
- " 7 astore_0\n" +
- " 8 return\n" +
+ " 0 new java.lang.Object [3]\n" +
+ " 3 dup\n" +
+ " 4 invokespecial java.lang.Object() [8]\n" +
+ " 7 checkcast java.lang.Object [3]\n" +
+ " 10 astore_0\n" +
+ " 11 return\n" +
" Line numbers:\n" +
" [pc: 0, line: 6]\n" +
- " [pc: 8, line: 7]\n" +
+ " [pc: 11, line: 7]\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #14 @NonNull(\n" +
+ " target type = 0x44 NEW\n" +
+ " offset = 0\n" +
+ " )\n" +
+ " #14 @NonNull(\n" +
+ " target type = 0x47 CAST\n" +
+ " offset = 7\n" +
+ " type argument index = 0\n" +
+ " )\n" +
" \n" +
" // Method descriptor #6 ()V\n" +
" // Stack: 1, Locals: 1\n" +
@@ -1454,7 +1478,7 @@ public class JSR308SpecSnippetTests extends AbstractRegressionTest {
" Local variable table:\n" +
" [pc: 0, pc: 11] local: this index: 0 type: X\n" +
" RuntimeInvisibleTypeAnnotations: \n" +
- " #16 @NonNull(\n" +
+ " #14 @NonNull(\n" +
" target type = 0x44 NEW\n" +
" offset = 4\n" +
" )\n" +
@@ -1475,7 +1499,7 @@ public class JSR308SpecSnippetTests extends AbstractRegressionTest {
" [pc: 0, pc: 11] local: this index: 0 type: X\n" +
" [pc: 0, pc: 11] local: x index: 1 type: int\n" +
" RuntimeInvisibleTypeAnnotations: \n" +
- " #16 @NonNull(\n" +
+ " #14 @NonNull(\n" +
" target type = 0x44 NEW\n" +
" offset = 4\n" +
" )\n" +
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
index dc55b3d153..dca6633675 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
@@ -17,6 +17,7 @@
* Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
* Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator
* Bug 409246 - [1.8][compiler] Type annotations on catch parameters not handled properly
+ * Bug 415541 - [1.8][compiler] Type annotations in the body of static initializer get dropped
*******************************************************************************/
package org.eclipse.jdt.internal.compiler;
@@ -1562,6 +1563,10 @@ public class ClassFile implements TypeConstants, TypeIds {
true);
}
+ if ((this.produceAttributes & ClassFileConstants.ATTR_TYPE_ANNOTATION) != 0) {
+ attributesNumber += generateTypeAnnotationsOnCodeAttribute();
+ }
+
// update the number of attributes
// ensure first that there is enough space available inside the contents array
if (codeAttributeAttributeOffset + 2 >= this.contents.length) {
@@ -1672,6 +1677,10 @@ public class ClassFile implements TypeConstants, TypeIds {
true);
}
+ if ((this.produceAttributes & ClassFileConstants.ATTR_TYPE_ANNOTATION) != 0) {
+ attributesNumber += generateTypeAnnotationsOnCodeAttribute();
+ }
+
// update the number of attributes
// ensure first that there is enough space available inside the contents array
if (codeAttributeAttributeOffset + 2 >= this.contents.length) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java
index 779d7cea86..cb344d21b7 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java
@@ -19,6 +19,8 @@
* bug 383368 - [compiler][null] syntactic null analysis for field references
* bug 401017 - [compiler][null] casted reference to @Nullable field lacks a warning
* bug 400761 - [compiler][null] null may be return as boolean without a diagnostic
+ * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for
+ * Bug 415541 - [1.8][compiler] Type annotations in the body of static initializer get dropped
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.ast;
@@ -57,8 +59,6 @@ public CastExpression(Expression expression, TypeReference type) {
this.expression = expression;
this.type = type;
type.bits |= ASTNode.IgnoreRawTypeCheck; // no need to worry about raw type usage
- if ((this.type.bits & ASTNode.HasTypeAnnotations) != 0)
- this.bits |= ASTNode.GenerateCheckcast;
}
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
@@ -422,11 +422,12 @@ public boolean checkUnsafeCast(Scope scope, TypeBinding castType, TypeBinding ex
*/
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
int pc = codeStream.position;
+ boolean annotatedCast = (this.type.bits & ASTNode.HasTypeAnnotations) != 0;
boolean needRuntimeCheckcast = (this.bits & ASTNode.GenerateCheckcast) != 0;
if (this.constant != Constant.NotAConstant) {
- if (valueRequired || needRuntimeCheckcast) { // Added for: 1F1W9IG: IVJCOM:WINNT - Compiler omits casting check
+ if (valueRequired || needRuntimeCheckcast || annotatedCast) { // Added for: 1F1W9IG: IVJCOM:WINNT - Compiler omits casting check
codeStream.generateConstant(this.constant, this.implicitConversion);
- if (needRuntimeCheckcast) {
+ if (needRuntimeCheckcast || annotatedCast) {
codeStream.checkcast(this.type, this.resolvedType);
}
if (!valueRequired) {
@@ -438,7 +439,7 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean
return;
}
this.expression.generateCode(currentScope, codeStream, valueRequired || needRuntimeCheckcast);
- if (needRuntimeCheckcast && this.expression.postConversionType(currentScope) != this.resolvedType.erasure()) { // no need to issue a checkcast if already done as genericCast
+ if (annotatedCast || (needRuntimeCheckcast && this.expression.postConversionType(currentScope) != this.resolvedType.erasure())) { // no need to issue a checkcast if already done as genericCast
codeStream.checkcast(this.type, this.resolvedType);
}
if (valueRequired) {

Back to the top