[junit tests] Bug 384458 - debug shows value of variable in another
scope
diff --git a/org.eclipse.jdt.debug.tests/testprograms/LocalVariableTests2.java b/org.eclipse.jdt.debug.tests/testprograms/LocalVariableTests2.java
new file mode 100644
index 0000000..a82f45b
--- /dev/null
+++ b/org.eclipse.jdt.debug.tests/testprograms/LocalVariableTests2.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+/**
+ * test case for https://bugs.eclipse.org/bugs/show_bug.cgi?id=384458
+ */
+public class LocalVariableTests2 {
+	static String[] a = new String[] { "0", "1", "2" };
+	public static String att = "something";
+	
+	public void m1() {
+		int[] a = new int[] { 101, 102 };
+		System.err.println(a[1]);
+	}
+	
+	public void m2(String att) {
+		if (att == null) {
+			System.out.println("att is null");
+		}
+		else {
+			System.out.println("att is not null");
+		}
+	}
+	
+	public static void main(String[] args) {
+		LocalVariableTests2 t2 = new LocalVariableTests2();
+		t2.m1();
+		t2.m2(null);
+	}
+}
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java
index 897d5d1..0501081 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java
@@ -172,7 +172,7 @@
 	public static final String ONE_SEVEN_PROJECT_NAME = "OneSeven";
 	public static final String BOUND_JRE_PROJECT_NAME = "BoundJRE";
 
-	final String[] LAUNCH_CONFIG_NAMES_1_4 = {"LargeSourceFile", "LotsOfFields", "Breakpoints", "InstanceVariablesTests", "LocalVariablesTests", "StaticVariablesTests",
+	final String[] LAUNCH_CONFIG_NAMES_1_4 = {"LargeSourceFile", "LotsOfFields", "Breakpoints", "InstanceVariablesTests", "LocalVariablesTests", "LocalVariableTests2", "StaticVariablesTests",
 			"DropTests", "ThrowsNPE", "ThrowsException", "org.eclipse.debug.tests.targets.Watchpoint", "org.eclipse.debug.tests.targets.CallLoop", "A",
 			"HitCountLooper", "CompileError", "MultiThreadedLoop", "HitCountException", "MultiThreadedException", "MultiThreadedList", "MethodLoop", "StepFilterOne",
 			"StepFilterFour", "EvalArrayTests", "EvalSimpleTests", "EvalTypeTests", "EvalNestedTypeTests", "EvalTypeHierarchyTests", "WorkingDirectoryTest", 
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/LocalVariableTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/LocalVariableTests.java
index 2c923bd..6bddee1 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/LocalVariableTests.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/core/LocalVariableTests.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2000, 2006 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
@@ -21,6 +21,9 @@
 import org.eclipse.jdt.debug.core.IJavaThread;
 import org.eclipse.jdt.debug.core.IJavaVariable;
 import org.eclipse.jdt.debug.tests.AbstractDebugTest;
+import org.eclipse.jdt.internal.debug.core.model.JDIArrayValue;
+import org.eclipse.jdt.internal.debug.core.model.JDILocalVariable;
+import org.eclipse.jdt.internal.debug.core.model.JDINullValue;
 
 public class LocalVariableTests extends AbstractDebugTest implements IValueDetailListener {
 	
@@ -30,6 +33,55 @@
 		super(name);
 	}
 
+	/**
+	 * Tests if the correct local variable is found when it shadows a field variable
+	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=384458
+	 * @throws Exception
+	 */
+	public void testFindConflicting1() throws Exception {
+		String typeName = "LocalVariableTests2";
+		ILineBreakpoint bp = createLineBreakpoint(21, typeName);		
+		
+		IJavaThread thread= null;
+		try {
+			thread= launchToLineBreakpoint(typeName, bp);
+			IJavaStackFrame frame = (IJavaStackFrame)thread.getTopStackFrame();
+			IJavaVariable var = frame.findVariable("a");
+			assertTrue("The returned var should be a LocalVariable instance", var instanceof JDILocalVariable);
+			IValue value = var.getValue();
+			assertTrue("The value should be an array", value instanceof JDIArrayValue);
+			JDIArrayValue aval = (JDIArrayValue) value;
+			assertTrue("there should be two values in the array", aval.getSize() == 2);
+			assertEquals("The array kind should be integer", "int[]", aval.getReferenceTypeName());
+		} finally {
+			terminateAndRemove(thread);
+			removeAllBreakpoints();
+		}		
+	}
+	
+	/**
+	 * Tests if the correct parameter variable is found when it shadows a field variable
+	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=384458
+	 * @throws Exception
+	 */
+	public void testFindConflicting2() throws Exception {
+		String typeName = "LocalVariableTests2";
+		ILineBreakpoint bp = createLineBreakpoint(25, typeName);		
+		
+		IJavaThread thread= null;
+		try {
+			thread= launchToLineBreakpoint(typeName, bp);
+			IJavaStackFrame frame = (IJavaStackFrame)thread.getTopStackFrame();
+			IJavaVariable var = frame.findVariable("att");
+			assertTrue("The returned var should be a LocalVariable instance", var instanceof JDILocalVariable);
+			IValue value = var.getValue();
+			assertTrue("The value should be a String", value instanceof JDINullValue);
+		} finally {
+			terminateAndRemove(thread);
+			removeAllBreakpoints();
+		}		
+	}
+	
 	public void testSimpleVisibility() throws Exception {
 		String typeName = "LocalVariablesTests";