Skip to content

Commit

Permalink
Fixed the issues to set conditional breakpoint in java.io.File class
Browse files Browse the repository at this point in the history
  • Loading branch information
SougandhS committed Sep 3, 2024
1 parent be4bbd6 commit c3209f7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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");
}

}

/////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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$
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c3209f7

Please sign in to comment.