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

Bug 75643

Summary: class cast exception evaluating detail formatter
Product: [Eclipse Project] JDT Reporter: Darin Wright <darin.eclipse>
Component: DebugAssignee: Darin Wright <darin.eclipse>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r
Version: 3.0   
Target Milestone: 3.1 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Darin Wright CLA 2004-10-05 10:25:24 EDT
I added a detail formatter as follows for Hastable, trying to come up with a 
workaround for bug 75413 for DJ.

int max = size() - 1;
StringBuffer buf = new StringBuffer();
Iterator it = entrySet().iterator();

buf.append("{");
for (int i = 0; i <= max; i++) {
    Map.Entry e = (Map.Entry) (it.next());
        Object key = e.getKey();
        Object value = e.getValue();
        buf.append((key   == this ? "(this Map)" : key) + "=" +
                   (value == this ? "(this Map)" : value));

    if (i < max)
	buf.append(",\n");
}
buf.append("}");
return buf.toString();

When the detail formatter is invoked, I get a classcast exception.

!ENTRY org.eclipse.jdt.debug 4 120 Oct 05, 2004 09:13:10.703
!MESSAGE Exception processing async thread queue
!SUBENTRY 1 org.eclipse.jdt.debug 4 120 Oct 05, 2004 09:13:10.703
!MESSAGE Exception processing async thread queue
!STACK 0
java.lang.ClassCastException: 
org/eclipse/jdt/internal/debug/core/model/JDIObjectValue incompatible with 
org/eclipse/jdt/debug/core/IJavaPrimitiveValue
	at 
org.eclipse.jdt.internal.debug.eval.ast.instructions.ConditionalJump.execute
(ConditionalJump.java:27)
	at org.eclipse.jdt.internal.debug.eval.ast.engine.Interpreter.execute
(Interpreter.java:50)
	at org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine$1
$EvaluationRunnable.run(ASTEvaluationEngine.java:330)
	at org.eclipse.jdt.internal.debug.core.model.JDIThread.runEvaluation
(JDIThread.java:659)
	at 
org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine$EvalRunnable
.run(ASTEvaluationEngine.java:364)
	at org.eclipse.jdt.internal.debug.core.model.JDIThread$ThreadJob.run
(JDIThread.java:2511)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:66)
Comment 1 Luc Bourlier CLA 2004-10-05 16:48:18 EDT
Fixed.
There was a problem when trying to evaluate an 'if' statement, with as 'then'
body an expression/statement that returns an value, if the 'then' body was not
delimited by '{' '}'.
for example:

if (true)
    toString();


When a statement is an method call that returns an value, a pop instruction is
added to remove the result of the method call from the execution stack.
To correctly create an 'if' statement, we need to know the size (in number of
instruction) of each part of the 'if' (condition, then body, else body).
But the pop instruction were not correctly created, and always returned a size
of 1, instead of 1 + the size of the operation which created the value to be
removed from the stack.
In result, the 'if' were not correctly created, the jumps were not added at the
right positions.

Pop - modified so it can be correctly initialized, and then return the correct
information.
ASTInstructionCompiler - updated to correctly create the pop instruction. Added
an helper method.
Comment 2 Luc Bourlier CLA 2004-10-05 16:49:36 EDT
The walkaround is to add '{' '}' around the then/else body of the if.

Please verify, Darin W.
Comment 3 Darin Wright CLA 2004-10-13 14:10:24 EDT
Verified.
Comment 4 Darin Wright CLA 2005-03-15 17:14:45 EST
*** Bug 88064 has been marked as a duplicate of this bug. ***