Skip to content

Commit

Permalink
ArrayIndexOutOfBoundsException in Parser due to static init block (#3524
Browse files Browse the repository at this point in the history
)

issue #3506
  • Loading branch information
mpalat authored Jan 7, 2025
1 parent dd00bad commit ee64a16
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2024 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -3477,6 +3477,9 @@ private boolean isAFieldDeclarationInRecord() {
continue;
nestingTypeAndMethod = this.recordNestedMethodLevels.get(node);
if (nestingTypeAndMethod != null) { // record declaration is done yet
if (nestingTypeAndMethod[0] != this.nestedType
|| nestingTypeAndMethod[1] != this.nestedMethod[this.nestedType])
return false;
recordIndex = i;
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2024 IBM Corporation and others.
* Copyright (c) 2019, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -28,7 +28,7 @@ public class RecordsRestrictedClassTest extends AbstractRegressionTest {
static {
// TESTS_NUMBERS = new int [] { 40 };
// TESTS_RANGE = new int[] { 1, -1 };
// TESTS_NAMES = new String[] { "testIssue1641"};
// TESTS_NAMES = new String[] { "testBug3504_1"};
}

public static Class<?> testClass() {
Expand Down Expand Up @@ -9591,4 +9591,29 @@ public static void main(String [] args) {
},
"OK!");
}
public void testBug3504_1() {
runNegativeTest(
new String[] {
"X.java",
"""
class X {
public static void main(String[] args) {
record R(int x) {
static {
static int i = 0;
}
}
R r = new R(100);
System.out.println(r.x());
}
}
"""
},
"----------\n" +
"1. ERROR in X.java (at line 5)\n" +
" static int i = 0;\n" +
" ^\n" +
"Illegal modifier for the variable i; only final is permitted\n" +
"----------\n");
}
}

0 comments on commit ee64a16

Please sign in to comment.