Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 150652

Summary: [evaluation] Force early return
Product: [Eclipse Project] JDT Reporter: Darin Wright <darin.eclipse>
Component: DebugAssignee: Curtis Windatt <curtis.windatt.public>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: carsten.hammer, Michael_Rennie, mlists
Version: 3.2   
Target Milestone: 3.3 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 174684    
Bug Blocks:    
Attachments:
Description Flags
patch
none
upated patch
none
work in progress none

Description Darin Wright CLA 2006-07-14 10:44:45 EDT
JavaSE6 provides the debugger with support to "force early return" from a method. We should expose this as special evaluation action "Force Return".

The action should only enable when there is a debug context (as the other evaluation actions). When in a void method, the action should enable when there is no selection (otherwise a selection is required to have an expression to evaluate the return value). We should evaluate the expression to verify that the return value is of a compatible type with the method return type.

The action should be available from the Java editor, Display view, and variables view detail pane.
Comment 1 Darin Wright CLA 2007-02-16 13:49:55 EST
Created attachment 59181 [details]
patch

Work in progress. Migrates debug action sets to use menus extension point to allow us to use commands and handlers for evaluation actions.
Comment 2 Darin Wright CLA 2007-02-19 15:25:16 EST
Created attachment 59310 [details]
upated patch
Comment 3 Darin Wright CLA 2007-02-19 15:25:35 EST
Filed bug 174684 against UI for activeWhen problem.
Comment 4 Darin Wright CLA 2007-03-13 12:52:53 EDT
Released new API to support this feature in the Java debugger.

IJavaThread.canForceReturn()
IJavaThread.forceReturn(IJavaValue)
IJavaDebugTarget.supportsForceReturn()

Added tests. Tests only run (to completion) on 1.6. Tests bail (but pass) when a VM does not support the feature.
Comment 5 Mike Wilson CLA 2007-03-13 13:51:58 EDT
+1
Comment 6 Michael Rennie CLA 2007-03-13 14:57:57 EDT
*** Bug 154231 has been marked as a duplicate of this bug. ***
Comment 7 Darin Wright CLA 2007-03-13 17:14:14 EDT
Created attachment 60733 [details]
work in progress

updated patch
Comment 8 Darin Wright CLA 2007-03-14 16:13:48 EDT
Fixed. Released new "Force Return" action with key-binding "Alt-Shift-F".

Feature only enables on 1.6 and works for top and non-top stack frames as long as there are no native methods in the way (i.e. we can't force a return from a native method). I moved the API for forcing return from the IJavaThread to IJavaStackFrame to give more flexibility on implementation for non-top frames. This is a brand new API so it doesn't break anyone.

Action appears in Run menu (top level), Java editor, Variables view, and Display View.

I did not migrate to the new menu/commands extensions. We should do that work separately, time permitting.
Comment 9 Darin Wright CLA 2007-03-14 16:14:29 EDT
Please verify, Curtis. I added tests for force return in non-top frames as well.
Comment 10 Curtis Windatt CLA 2007-03-15 17:19:28 EDT
Verified

Having enablesFor equal to '+' on the detail pane action is a little strange, since you don't need a selection in the display or editor views.

An icon would be helpful.  Maybe something like the step return icon, but with a red arrow instead of a yellow one.
Comment 11 Carsten Hammer CLA 2020-09-27 13:09:05 EDT
The code added here introduced the following bug that is still there in latest version:

Bug: Call to String.equals(org.eclipse.jdt.debug.core.IJavaValue) in org.eclipse.jdt.internal.debug.ui.actions.ForceReturnAction.displayResult(IEvaluationResult)
 
 This method calls equals(Object) on two references,  one of which is a class and the other an interface, where neither the class nor any of its non-abstract subclasses implement the interface. Therefore, the objects being compared are unlikely to be members of the same class at runtime (unless some application classes were not analyzed, or dynamic class loading can occur at runtime). According to the contract of equals(), objects of different classes should always compare as unequal; therefore, according to the contract defined by java.lang.Object.equals(Object), the result of this comparison will always be false at runtime.  
 
Rank: Scariest (4), 
confidence: High

Pattern: EC_UNRELATED_CLASS_AND_INTERFACE 

Type: EC, 
Category: CORRECTNESS (Correctness)<hr size="1" />


At ForceReturnAction.java:[line 65]
In method org.eclipse.jdt.internal.debug.ui.actions.ForceReturnAction.displayResult(IEvaluationResult)
Actual type org.eclipse.jdt.debug.core.IJavaValue
Expected String
Value loaded from value
String constant "V"
String.equals(Object) used to determine equality