Fixed bug 368435: [compiler] NPE while compile a method with unused
local
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java
index ecb7387..215c9e6 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 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
@@ -30,6 +30,100 @@
 	return buildAllCompliancesTestSuite(testClass());
 }
 
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=368435
+public void test368435() {
+	Map settings = getCompilerOptions();
+	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+	StringBuffer sourceCode = new StringBuffer(
+			"public class X {\n" +
+			"    public static void main(String[] args) {\n" +
+			"        System.out.println(\"SUCCESS\");\n" +
+			"    }\n" +
+			"    public void print() {\n" +
+			"        int i = 0;\n" +
+			"        if (System.currentTimeMillis() > 17000L) {\n" +
+			"            System.out.println(i++);\n");
+	
+	for (int i = 0; i < 5000; i++) {
+		sourceCode.append("\t\t		System.out.println(\"xyz\");\n");
+	}
+	sourceCode.append("}\n}\n}\n");
+	
+	this.runConformTest(
+			new String[] {
+					"X.java",
+					sourceCode.toString()
+			},
+			"SUCCESS",
+			null,
+			true,
+			null,
+			settings,
+			null);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=368435
+public void test368435b() {
+	Map settings = getCompilerOptions();
+	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+	StringBuffer sourceCode = new StringBuffer(
+			"public class X {\n" +
+			"    public static void main(String[] args) {\n" +
+			"        System.out.println(\"SUCCESS\");\n" +
+			"    }\n" +
+			"    public X() {\n" +
+			"        int i = 0;\n" +
+			"        if (System.currentTimeMillis() > 17000L) {\n" +
+			"            System.out.println(i++);\n");
+	
+	for (int i = 0; i < 5000; i++) {
+		sourceCode.append("\t\t		System.out.println(\"xyz\");\n");
+	}
+	sourceCode.append("}\n}\n}\n");
+	
+	this.runConformTest(
+			new String[] {
+					"X.java",
+					sourceCode.toString()
+			},
+			"SUCCESS",
+			null,
+			true,
+			null,
+			settings,
+			null);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=368435
+public void test368435c() {
+	Map settings = getCompilerOptions();
+	settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+	StringBuffer sourceCode = new StringBuffer(
+			"public class X {\n" +
+			"    public static void main(String[] args) {\n" +
+			"        System.out.println(\"SUCCESS\");\n" +
+			"    }\n" +
+			"    {\n" +
+			"        int i = 0;\n" +
+			"        if (System.currentTimeMillis() > 17000L) {\n" +
+			"            System.out.println(i++);\n");
+	
+	for (int i = 0; i < 5000; i++) {
+		sourceCode.append("\t\t		System.out.println(\"xyz\");\n");
+	}
+	sourceCode.append("}\n}\n}\n");
+	
+	this.runConformTest(
+			new String[] {
+					"X.java",
+					sourceCode.toString()
+			},
+			"SUCCESS",
+			null,
+			true,
+			null,
+			settings,
+			null);
+}
+
 public void test001() {
 	this.runConformTest(
 		new String[] {
diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html
index e5b35c3..941999b 100644
--- a/org.eclipse.jdt.core/buildnotes_jdt-core.html
+++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html
@@ -50,7 +50,9 @@
 <h2>What's new in this drop</h2>
 
 <h3>Problem Reports Fixed</h3>
-<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=366131">366131</a>
+<a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=368435">368435</a>
+[compiler] NPE while compile a method with unused local
+<br><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=366131">366131</a>
 [1.5][compiler] New generics compile error in Indigo SR1 for code that compiles in earlier Eclipse and javac
 <br><a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=302850">302850</a>
 13 failures in JavaModel tests for the N20100214-2000 Mac OS X - Cocoa test machine
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java
index 228e6e8..cf75940 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java
@@ -185,17 +185,10 @@
 				// a fatal error was detected during code generation, need to restart code gen if possible
 				if (e.compilationResult == CodeStream.RESTART_IN_WIDE_MODE) {
 					// a branch target required a goto_w, restart code gen in wide mode.
-					if (!restart) {
-						classFile.contentsOffset = problemResetPC;
-						classFile.methodCount--;
-						classFile.codeStream.resetInWideMode(); // request wide mode
-						restart = true;
-					} else {
-						// after restarting in wide mode, code generation failed again
-						// report a problem
-						restart = false;
-						abort = true;
-					}
+					classFile.contentsOffset = problemResetPC;
+					classFile.methodCount--;
+					classFile.codeStream.resetInWideMode(); // request wide mode
+					restart = true;
 				} else if (e.compilationResult == CodeStream.RESTART_CODE_GEN_FOR_UNUSED_LOCALS_MODE) {
 					classFile.contentsOffset = problemResetPC;
 					classFile.methodCount--;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java
index 3ccb0ba..2dd5580 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Clinit.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 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
@@ -118,16 +118,11 @@
 				// cases.
 				if (e.compilationResult == CodeStream.RESTART_IN_WIDE_MODE) {
 					// a branch target required a goto_w, restart code gen in wide mode.
-					if (!restart) {
-						classFile.contentsOffset = clinitOffset;
-						classFile.methodCount--;
-						classFile.codeStream.resetInWideMode(); // request wide mode
-						// restart method generation
-						restart = true;
-					} else {
-						classFile.contentsOffset = clinitOffset;
-						classFile.methodCount--;
-					}
+					classFile.contentsOffset = clinitOffset;
+					classFile.methodCount--;
+					classFile.codeStream.resetInWideMode(); // request wide mode
+					// restart method generation
+					restart = true;
 				} else if (e.compilationResult == CodeStream.RESTART_CODE_GEN_FOR_UNUSED_LOCALS_MODE) {
 					classFile.contentsOffset = clinitOffset;
 					classFile.methodCount--;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
index e7c790a..8dbcbeb 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 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
@@ -220,15 +220,10 @@
 		} catch (AbortMethod e) {
 			if (e.compilationResult == CodeStream.RESTART_IN_WIDE_MODE) {
 				// a branch target required a goto_w, restart code gen in wide mode.
-				if (!restart) {
-					classFile.contentsOffset = problemResetPC;
-					classFile.methodCount--;
-					classFile.codeStream.resetInWideMode(); // request wide mode
-					restart = true;
-				} else {
-					restart = false;
-					abort = true;
-				}
+				classFile.contentsOffset = problemResetPC;
+				classFile.methodCount--;
+				classFile.codeStream.resetInWideMode(); // request wide mode
+				restart = true;
 			} else if (e.compilationResult == CodeStream.RESTART_CODE_GEN_FOR_UNUSED_LOCALS_MODE) {
 				classFile.contentsOffset = problemResetPC;
 				classFile.methodCount--;