From 13f26fec453f7caad3eeb71673742c8ec476725d Mon Sep 17 00:00:00 2001 From: RoiSoleil Date: Tue, 6 May 2025 11:21:24 +0200 Subject: [PATCH] Unable to set a conditional breakpoint in a method with a parameter using generic extends X Fix #693 --- .../java7/Issue693.java | 25 +++++++++++++++++++ .../jdt/debug/tests/AbstractDebugTest.java | 2 +- .../debug/tests/eval/GenericsEval17Test.java | 12 +++++++++ .../eval/ast/engine/ASTEvaluationEngine.java | 6 ++++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 org.eclipse.jdt.debug.tests/java7/Issue693.java diff --git a/org.eclipse.jdt.debug.tests/java7/Issue693.java b/org.eclipse.jdt.debug.tests/java7/Issue693.java new file mode 100644 index 0000000000..27c85fc344 --- /dev/null +++ b/org.eclipse.jdt.debug.tests/java7/Issue693.java @@ -0,0 +1,25 @@ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class Issue693 { + static class Generic { + + private U u; + + public Generic(U u) { + this.u = u; + } + + void test(Generic generic) { + System.out.println("tested " + this); + } + } + + public static void main(String[] args) { + Generic generic = new Generic<>(5); + generic.test(generic); + } +} \ No newline at end of file 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 f2d55068d0..849139d2cc 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 @@ -161,7 +161,6 @@ import com.sun.jdi.InternalException; import com.sun.jdi.InvocationException; - import junit.framework.TestCase; /** @@ -446,6 +445,7 @@ synchronized void assert17Project() { cfgs.add(createLaunchConfiguration(jp, "Bug567801")); cfgs.add(createLaunchConfiguration(jp, "Bug572782")); cfgs.add(createLaunchConfiguration(jp, "Bug576829")); + cfgs.add(createLaunchConfiguration(jp, "Issue693")); loaded17 = true; waitForBuild(); } diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/GenericsEval17Test.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/GenericsEval17Test.java index 1ee424e677..339305fcd3 100644 --- a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/GenericsEval17Test.java +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/eval/GenericsEval17Test.java @@ -141,6 +141,18 @@ public void testEvaluate_Bug576829_RecursiveMultipleGenerics_ObjectInstanceEvalu assertEquals("value is not false", "false", value.getValueString()); } + public void testEvaluate_Issue693() throws Exception { + createConditionalLineBreakpoint(17, "Issue693", "generic.u.intValue() == 5", true); + javaThread = launchToBreakpoint("Issue693"); + assertNotNull("The program did not suspend", javaThread); + + String snippet = "generic.u.intValue()"; + IValue value = doEval(javaThread, snippet); + + assertNotNull("value is null", value); + assertEquals("value is not 5", "5", value.getValueString()); + } + private void debugWithBreakpoint(String testClass, int lineNumber) throws Exception { createLineBreakpoint(lineNumber, testClass); javaThread = launchToBreakpoint(testClass); diff --git a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java index 21c2a7caab..decc9cb444 100644 --- a/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java +++ b/org.eclipse.jdt.debug/eval/org/eclipse/jdt/internal/debug/eval/ast/engine/ASTEvaluationEngine.java @@ -392,7 +392,11 @@ private void scanAndFixSignature(String genericSignature, String erasureSignatur * and also generic signature such as Ljava/util/function/Predicate<+Ljava/util/List;>; Ljava/util/Comparator<-TT;>; * which will fail to properly resolved to the type. */ - if (genericSignature.startsWith(String.valueOf(Signature.C_TYPE_VARIABLE)) || genericSignature.startsWith(String.valueOf(Signature.C_CAPTURE)) + if (genericSignature.startsWith(String.valueOf(Signature.C_TYPE_VARIABLE))) { + fixedSignature.append(genericSignature.substring(String.valueOf(Signature.C_TYPE_VARIABLE).length(), genericSignature.length() - 1)); + return; + } + if (genericSignature.startsWith(String.valueOf(Signature.C_CAPTURE)) || genericSignature.startsWith(String.valueOf(Signature.C_SUPER))) { fixedSignature.append(toDotQualified(erasureSignature)); return;