Bug 541110 - CCE in Instruction.popValue

Added filtering for the code locations used to create breakpoints.
Filter locations of synthetic methods in case we have more then one
candidate, but let at least one location in the list.

Change-Id: I8cce85fe90533bc05ea96ece953579442b7abaf9
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
diff --git a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/JavaLineBreakpoint.java b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/JavaLineBreakpoint.java
index 0b75fce..71ab3ca 100644
--- a/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/JavaLineBreakpoint.java
+++ b/org.eclipse.jdt.debug/model/org/eclipse/jdt/internal/debug/core/breakpoints/JavaLineBreakpoint.java
@@ -53,6 +53,7 @@
 import com.sun.jdi.ClassNotPreparedException;
 import com.sun.jdi.InterfaceType;
 import com.sun.jdi.Location;
+import com.sun.jdi.Method;
 import com.sun.jdi.NativeMethodException;
 import com.sun.jdi.ObjectReference;
 import com.sun.jdi.ReferenceType;
@@ -301,6 +302,10 @@
 			// available
 			return null;
 		}
+		locations = filterLocations(locations);
+		if (locations.isEmpty()) {
+			return null;
+		}
 		EventRequest[] requests = new EventRequest[locations.size()];
 		int i = 0;
 		for(Location location : locations) {
@@ -311,8 +316,30 @@
 	}
 
 	/**
-	 * Creates, installs, and returns a line breakpoint request at the given
-	 * location for this breakpoint.
+	 * Filter out locations which shouldn't be used for breakpoint creation (like lambda methods)
+	 *
+	 * @return non null list with filtered locations
+	 */
+	protected List<Location> filterLocations(List<Location> locations) {
+		if (locations.size() <= 1) {
+			return locations;
+		}
+		List<Location> result = new ArrayList<>();
+		for (Location location : locations) {
+			Method method = location.method();
+			if (!method.isSynthetic()) {
+				result.add(location);
+			}
+		}
+		// this is just a best guess: all locations are synthetic, so we peek the first one
+		if (result.isEmpty()) {
+			result.add(locations.get(0));
+		}
+		return result;
+	}
+
+	/**
+	 * Creates, installs, and returns a line breakpoint request at the given location for this breakpoint.
 	 */
 	protected BreakpointRequest createLineBreakpointRequest(Location location,
 			JDIDebugTarget target) throws CoreException {