Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 234637 Details for
Bug 415541
[1.8][compiler] Type annotations in the body of static initializer get dropped.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch to fix the issue and adjust the test
0001-Bug415541.patch (text/plain), 10.48 KB, created by
Andrew Clement
on 2013-08-21 17:58:35 EDT
(
hide
)
Description:
Patch to fix the issue and adjust the test
Filename:
MIME Type:
Creator:
Andrew Clement
Created:
2013-08-21 17:58:35 EDT
Size:
10.48 KB
patch
obsolete
>From 163d4f24990a28587477c6d10f98406ae07d529e Mon Sep 17 00:00:00 2001 >From: Andy Clement <aclement@gopivotal.com> >Date: Wed, 21 Aug 2013 14:54:48 -0700 >Subject: [PATCH] Bug415541 fix > >--- > .../regression/JSR308SpecSnippetTests.java | 52 ++++++++++++++++------ > .../eclipse/jdt/internal/compiler/ClassFile.java | 9 ++++ > .../jdt/internal/compiler/ast/CastExpression.java | 12 ++--- > 3 files changed, 54 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 ec3218c..8e8df46 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 dc55b3d..dca6633 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 242c4ba..f56db67 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; > >@@ -51,14 +53,14 @@ public class CastExpression extends Expression { > public Expression expression; > public TypeReference type; > public TypeBinding expectedType; // when assignment conversion to a given expected type: String s = (String) t; >+ public boolean annotatedCast; > > //expression.implicitConversion holds the cast for baseType casting > 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; >+ this.annotatedCast = (this.type.bits & ASTNode.HasTypeAnnotations) != 0; > } > > public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { >@@ -424,9 +426,9 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean > int pc = codeStream.position; > 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 || this.annotatedCast) { // Added for: 1F1W9IG: IVJCOM:WINNT - Compiler omits casting check > codeStream.generateConstant(this.constant, this.implicitConversion); >- if (needRuntimeCheckcast) { >+ if (needRuntimeCheckcast || this.annotatedCast) { > codeStream.checkcast(this.type, this.resolvedType); > } > if (!valueRequired) { >@@ -438,7 +440,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 (this.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) { >-- >1.7.11.2 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 415541
: 234637