Fixed bug 375248: AIOOBE inside twr with finally block
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java
index f05362f..251c0da 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java
@@ -3627,7 +3627,7 @@
 		"true");
 }
 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
-public void _test375248() {
+public void test375248() {
 	this.runConformTest(
 		new String[] {
 			"X.java",
@@ -3637,9 +3637,9 @@
 			"import java.net.URL;\n" +
 			"\n" +
 			"public class X {\n" +
-			"public static void main(String[] args) throws Exception {\n" +
-			"  System.out.println(\"Done\");\n" +
-			"}\n" +
+			"    public static void main(String[] args) throws Exception {\n" +
+			"      System.out.println(\"Done\");\n" +
+			"    }\n" +
 			"    public void foo() throws MalformedURLException {\n" +
 			"        URL url = new URL(\"dummy\"); //$NON-NLS-1$\n" +
 			"        try (InputStream is = url.openStream()) {\n" +
@@ -3657,7 +3657,7 @@
 		"Done");
 }
 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
-public void _test375248b() {
+public void test375248a() {
 	this.runConformTest(
 		new String[] {
 			"X.java",
@@ -3697,6 +3697,122 @@
 		},
 		"Done");
 }
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
+public void test375248b() {
+	this.runConformTest(
+		new String[] {
+			"X.java",
+			"import java.io.File;\n" +
+			"import java.io.IOException;\n" +
+			"import java.io.InputStream;\n" +
+			"import java.net.MalformedURLException;\n" +
+			"import java.net.URL;\n" +
+			"import java.nio.file.Path;\n" +
+			"import java.nio.file.StandardCopyOption;\n" +
+			"\n" +
+			"public class X {\n" +
+			"    public static void main(String[] args) throws Exception {\n" +
+			"      System.out.println(\"Done\");\n" +
+			"    }\n" +
+			"    public void executeImports() throws MalformedURLException {\n" +
+			"        for (int i = 0; i < 3; i++) {\n" +
+			"            URL url = new URL(\"dummy\"); //$NON-NLS-1$\n" +
+			"            if (url != null) {\n" +
+			"                Path target = new File(\"dummy\").toPath();\n" +
+			"                try (InputStream is = url.openStream()) {\n" +
+			"                    java.nio.file.Files.copy(is, target,\n" +
+			"                            StandardCopyOption.REPLACE_EXISTING);\n" +
+			"                } catch (IOException e) {\n" +
+			"                     continue;\n" +
+			"                } finally {\n" +
+			"                    try {\n" +
+			"                        java.nio.file.Files.delete(target);\n" +
+			"                    } catch (IOException e1) {\n" +
+			"\n" +
+			"                    }\n" +
+			"                }\n" +
+			"            }\n" +
+			"        }\n" +
+			"    }\n" +
+			"}\n",
+		},
+		"Done");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
+public void test375248c() {
+	this.runConformTest(
+		new String[] {
+			"X.java",
+			"import java.io.File;\n" +
+			"import java.io.IOException;\n" +
+			"import java.io.InputStream;\n" +
+			"import java.net.MalformedURLException;\n" +
+			"import java.net.URL;\n" +
+			"import java.nio.file.Path;\n" +
+			"import java.nio.file.StandardCopyOption;\n" +
+			"\n" +
+			"public class X implements AutoCloseable {\n" +
+			"	public void foo()  {\n" +
+			"        try (X x = new X()) {\n" +
+			"	     System.out.println(\"Try\");\n" +
+			"	     throw new Exception();\n" +
+			"        } catch (Exception e) {\n" +
+			"	     System.out.println(\"Catch\");\n"+ 
+			"             return;\n" +
+			"        } finally {\n" +
+			"        	System.out.println(\"Finally\");\n" +
+			"        }\n" +
+			"    }\n" +
+			"	public void close() {\n" +
+			"		System.out.println(\"Close\");\n" +
+			"	}\n" +
+			"	public static void main(String[] args) {\n" +
+			"		new X().foo();\n" +
+			"	}\n" +
+			"}\n" 
+		},
+		"Try\n" + 
+		"Close\n" + 
+		"Catch\n" + 
+		"Finally");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
+public void test375248d() {
+	this.runConformTest(
+		new String[] {
+			"X.java",
+			"import java.io.File;\n" +
+			"import java.io.IOException;\n" +
+			"import java.io.InputStream;\n" +
+			"import java.net.MalformedURLException;\n" +
+			"import java.net.URL;\n" +
+			"import java.nio.file.Path;\n" +
+			"import java.nio.file.StandardCopyOption;\n" +
+			"\n" +
+			"public class X implements AutoCloseable {\n" +
+			"	public void foo()  {\n" +
+			"        try (X x = new X()) {\n" +
+			"	     System.out.println(\"Try\");\n" +
+			"        } catch (Exception e) {\n" +
+			"	     System.out.println(\"Catch\");\n"+ 
+			"             return;\n" +
+			"        } finally {\n" +
+			"        	System.out.println(\"Finally\");\n" +
+			"           return;\n" +
+			"        }\n" +
+			"    }\n" +
+			"	public void close() {\n" +
+			"		System.out.println(\"Close\");\n" +
+			"	}\n" +
+			"	public static void main(String[] args) {\n" +
+			"		new X().foo();\n" +
+			"	}\n" +
+			"}\n" 
+		},
+		"Try\n" + 
+		"Close\n" + 
+		"Finally");
+}
 public static Class testClass() {
 	return TryWithResourcesStatementTest.class;
 }
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java
index 0534970..38dee8e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java
@@ -586,6 +586,7 @@
 		}
 	} finally {
 		this.declaredExceptionLabels = null;
+		this.resourceExceptionLabels = null;  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248
 	}
 	boolean tryBlockHasSomeCode = codeStream.position != pc;
 	// flag telling if some bytecodes were issued inside the try block
@@ -835,7 +836,7 @@
 public boolean generateSubRoutineInvocation(BlockScope currentScope, CodeStream codeStream, Object targetLocation, int stateIndex, LocalVariableBinding secretLocal) {
 
 	int resourceCount = this.resources.length;
-	if (resourceCount > 0) {
+	if (resourceCount > 0 && this.resourceExceptionLabels != null) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248
 		for (int i = resourceCount; i > 0; --i) {
 			// Disarm the handlers and take care of resource closure.
 			this.resourceExceptionLabels[i].placeEnd();