Bug562295 - Fix for NPE when remote evaluations

This fix only handles non-public fields. Methods
are not handled in this bug fix.


Change-Id: I6d7c0cd5eacaa74b569a16fc478f61052f110861
Signed-off-by: gayanper <gayanper@gmail.com>
diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/RemoteEvaluatorTests.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/RemoteEvaluatorTests.java
index 4ea3845..4c9c93f 100644
--- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/RemoteEvaluatorTests.java
+++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/RemoteEvaluatorTests.java
@@ -44,6 +44,22 @@
 		assertEquals("count is not 0", "0", value.getValueString());
 	}
 
+	public void testEvaluate_InInnerScope_PrivateFieldInSameScope() throws Exception {
+		debugWithBreakpoint("RemoteEvaluator", 20);
+		IValue value = evaluate("java.util.Arrays.asList(\"a\", \"b\", \"ac\").stream().filter(v -> this.Q_EMPTY.test(v)).count()");
+
+		assertNotNull("result is null", value);
+		assertEquals("count is not 0", "0", value.getValueString());
+	}
+
+	public void testEvaluate_InInnerScope_PrivateFieldInSameScope_WithoutThis() throws Exception {
+		debugWithBreakpoint("RemoteEvaluator", 20);
+		IValue value = evaluate("java.util.Arrays.asList(\"a\", \"b\", \"ac\").stream().filter(v -> Q_EMPTY.test(v)).count()");
+
+		assertNotNull("result is null", value);
+		assertEquals("count is not 0", "0", value.getValueString());
+	}
+
 	@Override
 	protected IJavaProject getProjectContext() {
 		return get18Project();
diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/RemoteEvaluatorBuilder.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/RemoteEvaluatorBuilder.java
index c3bedfb..34d5aa8 100644
--- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/RemoteEvaluatorBuilder.java
+++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/RemoteEvaluatorBuilder.java
@@ -1513,7 +1513,7 @@
 						} else {
 							// TODO: Fix this to use same method as visit(FieldAccess)
 							ITypeBinding declaringClass = vb.getDeclaringClass();
-							String newVarName = new String(LOCAL_VAR_PREFIX) + allocateNewVariable(declaringClass, "this"); //$NON-NLS-1$
+							String newVarName = allocateNewVariable(declaringClass, LOCAL_VAR_PREFIX.concat("this")); //$NON-NLS-1$
 							binder.bindThis(declaringClass, newVarName);
 							// buffer.append("this."); //$NON-NLS-1$
 							buffer.append(newVarName);
@@ -1799,7 +1799,7 @@
 		public boolean visit(ThisExpression node) {
 			ITypeBinding thisType = node.resolveTypeBinding();
 
-			String newVarName = new String(LOCAL_VAR_PREFIX) + allocateNewVariable(thisType, "this"); //$NON-NLS-1$
+			String newVarName = allocateNewVariable(thisType, LOCAL_VAR_PREFIX.concat("this")); //$NON-NLS-1$
 			binder.bindThis(thisType, newVarName);
 			// buffer.append("this."); //$NON-NLS-1$
 			buffer.append(newVarName);