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 193211 Details for
Bug 342757
ArrayIndexOutOfBoundsException in MethodInfoWithParameterAnnotations.getParameterAnnotations when generating method info for an inner class constructor with annotated parameter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression test
patch_342757.txt (text/plain), 11.08 KB, created by
Olivier Thomann
on 2011-04-13 21:40:22 EDT
(
hide
)
Description:
Proposed fix + regression test
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2011-04-13 21:40:22 EDT
Size:
11.08 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java,v >retrieving revision 1.2 >diff -u -r1.2 MethodInfoWithParameterAnnotations.java >--- compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java 10 May 2007 16:21:35 -0000 1.2 >+++ compiler/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java 14 Apr 2011 01:38:54 -0000 >@@ -1,15 +1,17 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2007 BEA Systems, Inc. >+ * Copyright (c) 2005, 2011 BEA Systems, Inc. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * > * Contributors: >- * tyeung@bea.com - initial API and implementation >+ * tyeung@bea.com - initial API and implementation >+ * IBM Corporation - fix for bug 342757 > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.classfmt; > >+import org.eclipse.jdt.core.Signature; > import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation; > > class MethodInfoWithParameterAnnotations extends MethodInfoWithAnnotations { >@@ -17,7 +19,18 @@ > > MethodInfoWithParameterAnnotations(MethodInfo methodInfo, AnnotationInfo[] annotations, AnnotationInfo[][] parameterAnnotations) { > super(methodInfo, annotations); >- this.parameterAnnotations = parameterAnnotations; >+ if (methodInfo.isConstructor()) { >+ int parametersCount = Signature.getParameterCount(methodInfo.getMethodDescriptor()); >+ if (parameterAnnotations.length < parametersCount) { >+ AnnotationInfo[][] temp = new AnnotationInfo[parametersCount][]; >+ System.arraycopy(parameterAnnotations, 0, temp, 1, parameterAnnotations.length); >+ this.parameterAnnotations = temp; >+ } else { >+ this.parameterAnnotations = parameterAnnotations; >+ } >+ } else { >+ this.parameterAnnotations = parameterAnnotations; >+ } > } > > public IBinaryAnnotation[] getParameterAnnotations(int index) { >Index: model/org/eclipse/jdt/internal/core/util/Disassembler.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Disassembler.java,v >retrieving revision 1.100 >diff -u -r1.100 Disassembler.java >--- model/org/eclipse/jdt/internal/core/util/Disassembler.java 27 Aug 2009 15:27:02 -0000 1.100 >+++ model/org/eclipse/jdt/internal/core/util/Disassembler.java 14 Apr 2011 01:38:55 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -546,11 +546,25 @@ > IRuntimeInvisibleParameterAnnotationsAttribute attribute = (IRuntimeInvisibleParameterAnnotationsAttribute) runtimeInvisibleParameterAnnotationsAttribute; > invisibleParameterAnnotations = attribute.getParameterAnnotations(); > length = invisibleParameterAnnotations.length; >+ if (length > 0) { >+ int parameterNamesLength = parameterNames.length; >+ if (length < parameterNamesLength) { >+ System.arraycopy(invisibleParameterAnnotations, 0, (invisibleParameterAnnotations = new IParameterAnnotation[parameterNamesLength]), 1, length); >+ length = parameterNamesLength; >+ } >+ } > } > if (runtimeVisibleParameterAnnotationsAttribute != null) { > IRuntimeVisibleParameterAnnotationsAttribute attribute = (IRuntimeVisibleParameterAnnotationsAttribute) runtimeVisibleParameterAnnotationsAttribute; > visibleParameterAnnotations = attribute.getParameterAnnotations(); > length = visibleParameterAnnotations.length; >+ if (length > 0) { >+ int parameterNamesLength = parameterNames.length; >+ if (length < parameterNamesLength) { >+ System.arraycopy(visibleParameterAnnotations, 0, (visibleParameterAnnotations = new IParameterAnnotation[parameterNamesLength]), 1, length); >+ length = parameterNamesLength; >+ } >+ } > } > int insertionPosition = CharOperation.indexOf('(', methodHeader) + 1; > int start = 0; >@@ -561,15 +575,15 @@ > stringBuffer.append(' '); > } > int stringBufferSize = stringBuffer.length(); >- if (runtimeVisibleParameterAnnotationsAttribute != null) { >- disassembleAsModifier((IRuntimeVisibleParameterAnnotationsAttribute) runtimeVisibleParameterAnnotationsAttribute, stringBuffer, i, lineSeparator, tabNumber, mode); >+ if (visibleParameterAnnotations != null) { >+ disassembleAsModifier(visibleParameterAnnotations, stringBuffer, i, lineSeparator, tabNumber, mode); > } >- if (runtimeInvisibleParameterAnnotationsAttribute != null) { >+ if (invisibleParameterAnnotations != null) { > if (stringBuffer.length() != stringBufferSize) { > stringBuffer.append(' '); > stringBufferSize = stringBuffer.length(); > } >- disassembleAsModifier((IRuntimeInvisibleParameterAnnotationsAttribute) runtimeInvisibleParameterAnnotationsAttribute, stringBuffer, i, lineSeparator, tabNumber, mode); >+ disassembleAsModifier(invisibleParameterAnnotations, stringBuffer, i, lineSeparator, tabNumber, mode); > } > if (i == 0 && stringBuffer.length() != stringBufferSize) { > stringBuffer.append(' '); >@@ -1862,21 +1876,14 @@ > } > } > >- private void disassembleAsModifier(IRuntimeInvisibleParameterAnnotationsAttribute runtimeInvisibleParameterAnnotationsAttribute, StringBuffer buffer, int index, String lineSeparator, int tabNumber, int mode) { >- IParameterAnnotation[] parameterAnnotations = runtimeInvisibleParameterAnnotationsAttribute.getParameterAnnotations(); >- if (parameterAnnotations.length > index) { >- disassembleAsModifier(parameterAnnotations[index], buffer, lineSeparator, tabNumber + 1, mode); >- } >- } >- >- private void disassembleAsModifier(IRuntimeVisibleParameterAnnotationsAttribute runtimeVisibleParameterAnnotationsAttribute, StringBuffer buffer, int index, String lineSeparator, int tabNumber, int mode) { >- IParameterAnnotation[] parameterAnnotations = runtimeVisibleParameterAnnotationsAttribute.getParameterAnnotations(); >+ private void disassembleAsModifier(IParameterAnnotation[] parameterAnnotations, StringBuffer buffer, int index, String lineSeparator, int tabNumber, int mode) { > if (parameterAnnotations.length > index) { > disassembleAsModifier(parameterAnnotations[index], buffer, lineSeparator, tabNumber + 1, mode); > } > } > > private void disassembleAsModifier(IParameterAnnotation parameterAnnotation, StringBuffer buffer, String lineSeparator, int tabNumber, int mode) { >+ if (parameterAnnotation == null) return; > IAnnotation[] annotations = parameterAnnotation.getAnnotations(); > for (int i = 0, max = annotations.length; i < max; i++) { > if (i > 0) { >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v >retrieving revision 1.244 >diff -u -r1.244 AbstractJavaModelTests.java >--- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 4 Mar 2011 13:51:47 -0000 1.244 >+++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 14 Apr 2011 01:38:56 -0000 >@@ -789,7 +789,7 @@ > assertEquals("Unexpected annotations", expected, actual); > } > >- private void appendAnnotation(StringBuffer buffer, IAnnotation annotation) throws JavaModelException { >+ protected void appendAnnotation(StringBuffer buffer, IAnnotation annotation) throws JavaModelException { > buffer.append('@'); > buffer.append(annotation.getElementName()); > IMemberValuePair[] members = annotation.getMemberValuePairs(); >Index: src/org/eclipse/jdt/core/tests/model/ClassFileTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassFileTests.java,v >retrieving revision 1.50 >diff -u -r1.50 ClassFileTests.java >--- src/org/eclipse/jdt/core/tests/model/ClassFileTests.java 7 Sep 2010 03:17:36 -0000 1.50 >+++ src/org/eclipse/jdt/core/tests/model/ClassFileTests.java 14 Apr 2011 01:38:56 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -207,7 +207,14 @@ > "import java.lang.annotation.Retention;\n" + > "import java.lang.annotation.RetentionPolicy;\n" + > "@Retention(value = RetentionPolicy.CLASS)\n" + >- "public @interface MyAnnotation3 {}" >+ "public @interface MyAnnotation3 {}", >+ "test342757/X.java", >+ "package test342757;\n" + >+ "public class X {\n" + >+ " class B {\n" + >+ " public B(@Deprecated String s) {}\n" + >+ " }\n" + >+ "}", > }; > addLibrary(javaProject, "lib.jar", "libsrc.zip", pathAndContents, JavaCore.VERSION_1_5); > this.jarRoot = javaProject.getPackageFragmentRoot(getFile("/P/lib.jar")); >@@ -516,6 +523,32 @@ > } > > /* >+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=342757 >+ */ >+public void testAnnotations26() throws JavaModelException { >+ IType type = this.jarRoot.getPackageFragment("test342757").getClassFile("X$B.class").getType(); >+ IMethod[] methods = type.getMethods(); >+ String expected = "@java.lang.Deprecated\n"; >+ StringBuffer buffer = new StringBuffer(); >+ for (int i = 0, max = methods.length; i < max; i++) { >+ ILocalVariable[] parameters = methods[i].getParameters(); >+ for (int j = 0, max2 = parameters.length; j < max2; j++) { >+ IAnnotation[] annotations = parameters[j].getAnnotations(); >+ for (int n = 0; n < annotations.length; n++) { >+ IAnnotation annotation = annotations[n]; >+ appendAnnotation(buffer, annotation); >+ buffer.append("\n"); >+ } >+ } >+ } >+ String actual = buffer.toString(); >+ if (!expected.equals(actual)) { >+ System.out.println(displayString(actual, 2) + this.endChar); >+ } >+ assertEquals("Unexpected annotations", expected, actual); >+} >+ >+/* > * Ensures that no exception is thrown for a .class file name with a dot > * (regression test for bug 114140 assertion failed when opening a class file not not the classpath) > */
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 342757
:
193190
|
193211
|
193263