Skip to content

Commit

Permalink
NPE in AST: Cannot read the array length because "this.arguments" is
Browse files Browse the repository at this point in the history
null

fixes eclipse-jdt#2828
  • Loading branch information
stephan-herrmann committed Aug 16, 2024
1 parent d116b06 commit 4d2f13f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,10 @@ public TypeBinding resolveType(BlockScope scope) {

protected boolean isMissingTypeRelevant() {
if (this.binding != null && this.binding.isVarargs()) {
if (this.arguments.length < this.binding.parameters.length) {
int argLen = this.arguments != null ? this.arguments.length : 0;
if (0 < this.binding.parameters.length) {
// are all but the irrelevant varargs type present?
for (int i = 0; i < this.arguments.length; i++) {
for (int i = 0; i < argLen; i++) {
if ((this.binding.parameters[i].tagBits & TagBits.HasMissingType) != 0)
return true; // this one *is* relevant - actually this case is already detected during findConstructorBinding()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,10 @@ protected boolean isMissingTypeRelevant() {
}
if ((this.binding.returnType.tagBits & TagBits.HasMissingType) == 0
&& this.binding.isVarargs()) {
if (this.arguments.length < this.binding.parameters.length) {
int argLen = this.arguments != null ? this.arguments.length : 0;
if (argLen < this.binding.parameters.length) {
// are all but the irrelevant varargs type present?
for (int i = 0; i < this.arguments.length; i++) {
for (int i = 0; i < argLen; i++) {
if ((this.binding.parameters[i].tagBits & TagBits.HasMissingType) != 0)
return true; // this one *is* relevant - actually this case is already detected during findMethodBinding()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9702,6 +9702,46 @@ The constructor B(A, String...) refers to the missing type A
""";
runner.runNegativeTest();
}
public void testMissingClass_varargs4_noArg() {
// missing type in non-varargs position
if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // ignore different outcome below 1.8 since PR 2543
Runner runner = new Runner();
runner.testFiles = new String[] {
"p1/A.java",
"""
package p1;
public class A {}
""",
"p1/B.java",
"""
package p1;
public class B {
public B(A... a) {}
public void m(A... a) {}
}
"""
};
runner.runConformTest();

// delete binary file A (i.e. simulate removing it from classpath for subsequent compile)
Util.delete(new File(OUTPUT_DIR, "p1" + File.separator + "A.class"));
runner.shouldFlushOutputDirectory = false;

runner.testFiles = new String[] {
"p2/C.java",
"""
package p2;
import p1.B;
public class C {
void test(B b) {
new B();
b.m();
}
}
"""
};
runner.runConformTest();
}
public void testMissingClass_returnType_OK() {
if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // ignore different outcome below 1.8 since PR 2543
Runner runner = new Runner();
Expand Down

0 comments on commit 4d2f13f

Please sign in to comment.