Skip to content

Commit

Permalink
[Switch Expression] Assertion fails when IDE is launched with JVM opt…
Browse files Browse the repository at this point in the history
…ion -ea (eclipse-jdt#2367)

* Fixes eclipse-jdt#2366
  • Loading branch information
srikanth-sankaran authored Apr 19, 2024
1 parent 591700a commit 8cc65a5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,13 @@ public void aload(int iArg) {
public void aload_0() {
this.countLabels = 0;
this.stackDepth++;
pushTypeBinding(0);
if (this.stackDepth > this.stackMax) {
this.stackMax = this.stackDepth;
}
if (this.maxLocals == 0) {
this.maxLocals = 1;
}
pushTypeBinding(0);
if (this.classFileOffset >= this.bCodeStream.length) {
resizeByteArray();
}
Expand All @@ -354,12 +354,12 @@ public void aload_0() {
public void aload_1() {
this.countLabels = 0;
this.stackDepth++;
pushTypeBinding(1);
if (this.stackDepth > this.stackMax)
this.stackMax = this.stackDepth;
if (this.maxLocals <= 1) {
this.maxLocals = 2;
}
pushTypeBinding(1);
if (this.classFileOffset >= this.bCodeStream.length) {
resizeByteArray();
}
Expand All @@ -370,12 +370,12 @@ public void aload_1() {
public void aload_2() {
this.countLabels = 0;
this.stackDepth++;
pushTypeBinding(2);
if (this.stackDepth > this.stackMax)
this.stackMax = this.stackDepth;
if (this.maxLocals <= 2) {
this.maxLocals = 3;
}
pushTypeBinding(2);
if (this.classFileOffset >= this.bCodeStream.length) {
resizeByteArray();
}
Expand All @@ -386,12 +386,12 @@ public void aload_2() {
public void aload_3() {
this.countLabels = 0;
this.stackDepth++;
pushTypeBinding(3);
if (this.stackDepth > this.stackMax)
this.stackMax = this.stackDepth;
if (this.maxLocals <= 3) {
this.maxLocals = 4;
}
pushTypeBinding(3);
if (this.classFileOffset >= this.bCodeStream.length) {
resizeByteArray();
}
Expand Down Expand Up @@ -7706,7 +7706,9 @@ private TypeBinding retrieveLocalType(int currentPC, int resolvedPosition) {
private void pushTypeBinding(int resolvedPosition) {
if (!isSwitchStackTrackingActive())
return;
assert resolvedPosition < this.maxLocals;
if (resolvedPosition >= this.maxLocals) {
throw new AssertionError("Unexpected resolved position"); //$NON-NLS-1$
}
TypeBinding type = retrieveLocalType(this.position, resolvedPosition);
pushTypeBinding(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7426,4 +7426,45 @@ public static void main(String argv[]) {
},
"true\n42");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2366
// [Switch Expression] Assertion fails when IDE is launched with JVM option -ea
public void testIssue2366() {
if (this.complianceLevel < ClassFileConstants.JDK14)
return;
this.runConformTest(
new String[] {
"X.java",
"""
public class X {
public X() {
super();
}
public static void foo() {
X z;
while (((z = getObject()) != null)) {
z.bar();
}
System.out.println(switch(42) {
default -> {
try {
yield 42;
} finally {
}
}
});
}
public void bar() {
}
public static X getObject() {
return null;
}
public static void main(String[] args) {
new X().foo();
}
}
"""
},
"42");
}
}

0 comments on commit 8cc65a5

Please sign in to comment.