From c3209f7513738a6c4fe68186a519d7eee00f0dc0 Mon Sep 17 00:00:00 2001 From: sougandhs Date: Tue, 27 Aug 2024 13:55:55 +0530 Subject: [PATCH] Fixed the issues to set conditional breakpoint in java.io.File class --- .../testprograms/FileConditionSnippet2.java | 13 +++++ .../jdt/debug/tests/AbstractDebugTest.java | 8 ++- .../ConditionalBreakpointsWithFileClass.java | 57 +++++++++++++++++++ .../eval/ast/engine/ASTEvaluationEngine.java | 3 +- 4 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 org.eclipse.jdt.debug.tests/testprograms/FileConditionSnippet2.java create mode 100644 org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/ConditionalBreakpointsWithFileClass.java diff --git a/org.eclipse.jdt.debug.tests/testprograms/FileConditionSnippet2.java b/org.eclipse.jdt.debug.tests/testprograms/FileConditionSnippet2.java new file mode 100644 index 0000000000..216291136a --- /dev/null +++ b/org.eclipse.jdt.debug.tests/testprograms/FileConditionSnippet2.java @@ -0,0 +1,13 @@ +import java.io.File; + +public class FileConditionSnippet2 { + public static void main(String[] ecs) { + int i = 0; + File parent = new File("parent"); + File file = new File(parent,"test"); + System.out.println("COMPLETED"); + } + +} + +///////////////////////////////////////// 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 41e68b8e03..7e5f9661e8 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 @@ -184,7 +184,10 @@ public abstract class AbstractDebugTest extends TestCase implements IEvaluation public static final String BOUND_JRE_PROJECT_NAME = "BoundJRE"; public static final String CLONE_SUFFIX = "Clone"; - final String[] LAUNCH_CONFIG_NAMES_1_4 = {"LargeSourceFile", "LotsOfFields", "Breakpoints", "InstanceVariablesTests", "LocalVariablesTests", "LocalVariableTests2", "StaticVariablesTests", + final String[] LAUNCH_CONFIG_NAMES_1_4 = { "java.io.File", "FileConditionSnippet2", "LargeSourceFile", "LotsOfFields", + "Breakpoints", + "InstanceVariablesTests", + "LocalVariablesTests", "LocalVariableTests2", "StaticVariablesTests", "DropTests", "ThrowsNPE", "ThrowsException", "org.eclipse.debug.tests.targets.Watchpoint", "org.eclipse.debug.tests.targets.BreakpointsLocationBug344984", "org.eclipse.debug.tests.targets.CallLoop", "A", "HitCountLooper", "CompileError", "MultiThreadedLoop", "HitCountException", "MultiThreadedException", "MultiThreadedList", "MethodLoop", "StepFilterOne", @@ -1536,13 +1539,14 @@ protected IJavaThread launchToLineBreakpoint(String mainTypeName, ILineBreakpoin */ protected IJavaThread launchToLineBreakpoint(ILaunchConfiguration config, ILineBreakpoint bp, boolean register) throws Exception { DebugEventWaiter waiter= new DebugElementKindEventDetailWaiter(DebugEvent.SUSPEND, IJavaThread.class, DebugEvent.BREAKPOINT); - waiter.setTimeout(DEFAULT_TIMEOUT); + waiter.setTimeout(30000); waiter.setEnableUIEventLoopProcessing(enableUIEventLoopProcessingInWaiter()); Object suspendee= launchAndWait(config, waiter, register); assertTrue("suspendee was not an IJavaThread", suspendee instanceof IJavaThread); //$NON-NLS-1$ IJavaThread thread = (IJavaThread) suspendee; IBreakpoint hit = getBreakpoint(thread); + assertNotNull("suspended, but not by breakpoint", hit); //$NON-NLS-1$ assertEquals("hit un-registered breakpoint", bp, hit); //$NON-NLS-1$ assertTrue("suspended, but not by line breakpoint", hit instanceof ILineBreakpoint); //$NON-NLS-1$ diff --git a/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/ConditionalBreakpointsWithFileClass.java b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/ConditionalBreakpointsWithFileClass.java new file mode 100644 index 0000000000..fbef39c4a6 --- /dev/null +++ b/org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/breakpoints/ConditionalBreakpointsWithFileClass.java @@ -0,0 +1,57 @@ +package org.eclipse.jdt.debug.tests.breakpoints; + +import org.eclipse.jdt.debug.core.IJavaLineBreakpoint; +import org.eclipse.jdt.debug.core.IJavaThread; +import org.eclipse.jdt.debug.tests.AbstractDebugTest; + +public class ConditionalBreakpointsWithFileClass extends AbstractDebugTest { + + public ConditionalBreakpointsWithFileClass(String name) { + super(name); + } + + public void testFileConditionalBreakpointForTrue() throws Exception { + String typeName = "FileConditionSnippet2"; + IJavaLineBreakpoint bp = createLineBreakpoint(7, typeName); + createConditionalLineBreakpoint(374, "java.io.File", "child.equals(\"test\")", true); + + IJavaThread mainThread = null; + try { + mainThread = launchToLineBreakpoint(typeName, bp); + mainThread.resume(); + Thread.sleep(100); + int hitLine = 0; + if (mainThread.isSuspended()) { + hitLine = mainThread.getStackFrames()[0].getLineNumber(); + } + assertTrue("Should hit", (hitLine == 374) && (mainThread.isSuspended() == true)); + } finally { + bp.delete(); + terminateAndRemove(mainThread); + removeAllBreakpoints(); + } + } + + public void testFileConditionalBreakpointForFalse() throws Exception { + String typeName = "FileConditionSnippet2"; + IJavaLineBreakpoint bp = createLineBreakpoint(7, typeName); + createConditionalLineBreakpoint(374, "java.io.File", "child.equals(\"test2\")", true); + + IJavaThread mainThread = null; + try { + mainThread = launchToLineBreakpoint(typeName, bp); + mainThread.resume(); + Thread.sleep(100); + int hitLine = 0; + if (mainThread.isSuspended()) { + hitLine = mainThread.getStackFrames()[0].getLineNumber(); + } + assertFalse("Should hit", (hitLine == 374) && (mainThread.isSuspended() == true)); + } finally { + bp.delete(); + terminateAndRemove(mainThread); + removeAllBreakpoints(); + } + } + +} 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 310039540b..fbf79245aa 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 @@ -687,9 +687,10 @@ private ICompiledExpression createExpressionFromAST(String snippet, || problemId == IProblem.NotVisibleConstructor || problemId == IProblem.NotVisibleField || problemId == IProblem.NotVisibleType - || problemId == IProblem.UnexpectedStaticModifierForMethod) { + || problemId == IProblem.UnexpectedStaticModifierForMethod || problemId == IProblem.AmbiguousType) { continue; } + if (problem.isError()) { if (codeSnippetStart <= errorOffset && errorOffset <= codeSnippetEnd) {