diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java index 79bce007add..daf79f786c3 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/MethodInfoWithParameterAnnotations.java @@ -26,25 +26,29 @@ class MethodInfoWithParameterAnnotations extends MethodInfoWithAnnotations { } @Override public IBinaryAnnotation[] getParameterAnnotations(int index, char[] classFileName) { - try { - return this.parameterAnnotations == null ? null : this.parameterAnnotations[index]; - } catch (ArrayIndexOutOfBoundsException aioobe) { - // detailed reporting to track down https://bugs.eclipse.org/474081 - StringBuilder message = new StringBuilder("Mismatching number of parameter annotations, "); //$NON-NLS-1$ - message.append(index); - message.append('>'); - message.append(this.parameterAnnotations.length-1); - message.append(" in "); //$NON-NLS-1$ - message.append(getSelector()); - char[] desc = getGenericSignature(); - if (desc != null) - message.append(desc); - else - message.append(getMethodDescriptor()); - if (classFileName != null) - message.append(" in ").append(classFileName); //$NON-NLS-1$ - throw new IllegalStateException(message.toString(), aioobe); + if (this.parameterAnnotations != null) { + if (index < this.parameterAnnotations.length) { + return this.parameterAnnotations[index]; + } + if (Boolean.getBoolean("jdt.reject.parameterAnnotations.countMismatch")) { //$NON-NLS-1$ + // detailed reporting to track down https://bugs.eclipse.org/474081 + StringBuilder message = new StringBuilder("Mismatching number of parameter annotations, "); //$NON-NLS-1$ + message.append(index); + message.append('>'); + message.append(this.parameterAnnotations.length-1); + message.append(" in "); //$NON-NLS-1$ + message.append(getSelector()); + char[] desc = getGenericSignature(); + if (desc != null) + message.append(desc); + else + message.append(getMethodDescriptor()); + if (classFileName != null) + message.append(" in ").append(classFileName); //$NON-NLS-1$ + throw new IllegalStateException(message.toString()); + } } + return null; } @Override public int getAnnotatedParametersCount() { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_8.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_8.java index 695daeef763..45559f7b3a3 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_8.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_8.java @@ -31,6 +31,7 @@ @SuppressWarnings({ "rawtypes" }) public class ClassFileReaderTest_1_8 extends AbstractRegressionTest { static { +// TESTS_NAMES = new String[] { "testGH2625" }; } public static Test suite() { @@ -470,6 +471,33 @@ public void testBug548596() { ); } + public void testGH2625() { + String[] libs = getDefaultClassPaths(); + int len = libs.length; + System.arraycopy(libs, 0, libs = new String[len+1], 0, len); + // in this jar the num_parameters field of RuntimeInvisibleParameterAnnotations has been manually set to 2 + // (annotations on the 3-arg method a(Function,Object,long)): + libs[libs.length-1] = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "TestGH2625.jar"; + + runConformTest( + new String[] { + "Test.java", + """ + import a.A; + public class Test { + void test(A a) { + a.m(null, null, 0L); + } + } + """ + }, + "", + libs, + false, + null + ); + } + /** * Produce a nicely formatted type annotation for testing. Exercises the API for type annotations. * Output examples:
diff --git a/org.eclipse.jdt.core.tests.compiler/workspace/TestGH2625.jar b/org.eclipse.jdt.core.tests.compiler/workspace/TestGH2625.jar new file mode 100644 index 00000000000..698dfacf661 Binary files /dev/null and b/org.eclipse.jdt.core.tests.compiler/workspace/TestGH2625.jar differ