Skip to content

Commit

Permalink
[code select] Unexpected runtime error while computing a text hover: …
Browse files Browse the repository at this point in the history
…java.lang.NegativeArraySizeException (eclipse-jdt#3052)

* Fixes eclipse-jdt#3050
  • Loading branch information
srikanth-sankaran authored Oct 6, 2024
1 parent 81ab185 commit 9b4746e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ enum ScanContext {
private VanguardParser vanguardParser;
ConflictedParser activeParser = null;
private boolean consumingEllipsisAnnotations = false;
protected boolean multiCaseLabelComma = false;
public boolean multiCaseLabelComma = false;

public static final int RoundBracket = 0;
public static final int SquareBracket = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,36 @@ private record FooBar<T>(T object) implements Foo {
elements
);
}

// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3050
// [code select] Unexpected runtime error while computing a text hover: java.lang.NegativeArraySizeException
public void testIssue3050() throws JavaModelException {
this.wc = getWorkingCopy("/Resolve/src/Hover.java",
"""
interface Function<T, R> {
R apply(T t);
}
public class Hover {
void d() {
Function<Object, Object> f = d -> 2;
switch (f) {
case Function<?, ?> s -> {}
}
}
}
"""
);
String str = this.wc.getSource();
String selection = "Function";
int start = str.lastIndexOf(selection);
int length = selection.length();
IJavaElement[] elements = this.wc.codeSelect(start, length);
assertElementsEqual(
"Unexpected elements",
"Function [in [Working copy] Hover.java [in <default> [in src [in Resolve]]]]",
elements
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1459,14 +1459,16 @@ protected void consumeToken(int token) {
pushOnElementStack(K_BETWEEN_CASE_AND_COLONORARROW, this.expressionPtr);
break;
case TokenNameCOMMA :
switch (topKnownElementKind(SELECTION_OR_ASSIST_PARSER)) {
// for multi constant case stmt
// case MONDAY, FRIDAY
// if there's a comma, ignore the previous expression (constant)
// Which doesn't matter for the next constant
case K_BETWEEN_CASE_AND_COLONORARROW:
this.expressionPtr--;
this.expressionLengthStack[this.expressionLengthPtr]--;
if (this.scanner.multiCaseLabelComma) {
switch (topKnownElementKind(SELECTION_OR_ASSIST_PARSER)) {
// for multi constant case stmt
// case MONDAY, FRIDAY
// if there's a comma, ignore the previous expression (constant)
// Which doesn't matter for the next constant
case K_BETWEEN_CASE_AND_COLONORARROW:
this.expressionPtr--;
this.expressionLengthStack[this.expressionLengthPtr]--;
}
}
break;
case TokenNameARROW:
Expand Down

0 comments on commit 9b4746e

Please sign in to comment.