Skip to content

Commit

Permalink
Bug 545605 - Adjust ecj to change in JVMS 4.7.18./19. (#2628)
Browse files Browse the repository at this point in the history
Accept class files with mismatching parameter count vis-a-vis parameter annotations (which is legal since Java 9).

Also introduces system property jdt.reject.parameterAnnotations.countMismatch to get back the previous error reporting.

fixes #2625
  • Loading branch information
stephan-herrmann authored Jun 23, 2024
1 parent a62c379 commit 2feaa74
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
@SuppressWarnings({ "rawtypes" })
public class ClassFileReaderTest_1_8 extends AbstractRegressionTest {
static {
// TESTS_NAMES = new String[] { "testGH2625" };
}

public static Test suite() {
Expand Down Expand Up @@ -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:<br>
Expand Down
Binary file not shown.

0 comments on commit 2feaa74

Please sign in to comment.