Debugger and function calls

J

jan_bar

Hi,

when I stop a java program in a debugger (e.g. Eclipse), why I cannot call
methods like
System.out.println(someObject)
on data from my program? When I try to evaluate this, Eclipse says:
com.sun.jdi.InvalidTypeException: Type of the value not compatible with the
expected type. occured invoking method.

Thanks, Jan
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jan_bar schreef:
Hi,

when I stop a java program in a debugger (e.g. Eclipse), why I cannot call
methods like
System.out.println(someObject)
on data from my program? When I try to evaluate this, Eclipse says:
com.sun.jdi.InvalidTypeException: Type of the value not compatible with the
expected type. occured invoking method.

Try selecting an element and Ctrl+Shift+I, or right-click -> Inspect.
or Eclipse specific questions, see news.eclipse.org:eclipse.newcomer

HTH, H.

- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEfaIfe+7xMGD3itQRAtRNAJwIHJ/a8O1GyxBAixw1dotmvrxjFwCggq7e
4qJmkYT+VR7aPW8eRXRHsIk=
=hQ6g
-----END PGP SIGNATURE-----
 
J

jan_bar

To make the things clear, here is a sample:

public static void main(String args[]) {
String s = "hello";
s = null;//<-- breakpoint here
}

When the breakpoint is hit, I want to evalue expression
"System.out.println(s)", but Eclipse says
com.sun.jdi.InvalidTypeException: Type of the value not compatible with the
expected type. occured invoking method.

Where can I find advanced documentation about the Java/Eclipse debugger?

Thanks, Jan
 
J

jan_bar

Thanks, but this is not that easy, please see my other post. I am not sure
if this is Eclipse specific, but this migh be Java debugger limitation.

Jan
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jan_bar schreef:
To make the things clear, here is a sample:

public static void main(String args[]) {
String s = "hello";
s = null;//<-- breakpoint here
}

When the breakpoint is hit, I want to evalue expression
"System.out.println(s)", but Eclipse says
com.sun.jdi.InvalidTypeException: Type of the value not compatible with the
expected type. occured invoking method.

Normally, you should see s in the Variables view. If that isn’t there,
open it. If you then click on s, you will automatically see its String
representation. You can then click there and enter additional queries
if you like. Also in the expressions view, although I am also still
struggling with it.

Did you read the help documentation that comes with Eclipse? It is all
in there, albeit very terse.

H.

- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEfbj8e+7xMGD3itQRAkgWAJ4owWhfRhjNeRyfVfnFbNESKNlnxQCeN2vz
hQvz1gPmgutSXqLM3ZCR9G0=
=NR7R
-----END PGP SIGNATURE-----
 
O

Oliver Wong

jan_bar said:
To make the things clear, here is a sample:

public static void main(String args[]) {
String s = "hello";
s = null;//<-- breakpoint here
}

When the breakpoint is hit, I want to evalue expression
"System.out.println(s)", but Eclipse says
com.sun.jdi.InvalidTypeException: Type of the value not compatible with
the
expected type. occured invoking method.

If I put the above code in a class, add the breakpoint on the line with
the comment, run the debugger, switch to the Expression view, and add the
expression "System.out.println(s)", the expression evaluator correctly
reports that the expression evaluates to void.

In other words, it works when I try it.

- Oliver
 
C

Chris Uppal

Oliver said:
If I put the above code in a class, add the breakpoint on the line
with the comment, run the debugger, switch to the Expression view, and
add the expression "System.out.println(s)", the expression evaluator
correctly reports that the expression evaluates to void.

And prints "hello" to the console pane as a side-effect.

I.e. it works for me too. That's with Eclipse 3.1, and debugging using JDK
1.5.0_b6.

-- chris
 
J

jan_bar

Thanks for testing, in fact it works for me too, the sample was wrong.
Please try this:

public static void main(String args[]) {
System.out.println(args);

Object o = args;
System.out.println(o);// <- breakpoint
}

Both println's will print something on console but calling the same function
as expression doesn't work. Seems like Eclipse bug (3.1.2).

Regards, Jan
 
C

Chris Uppal

jan_bar said:
public static void main(String args[]) {
System.out.println(args);

Object o = args;
System.out.println(o);// <- breakpoint
}

Both println's will print something on console but calling the same
function as expression doesn't work. Seems like Eclipse bug (3.1.2).

Yes, I see the same error (my Eclipse is at 1.3.1). Eclipse bug or JVM bug.
Recompiling for 1.4, and running on a 1.4.2 JVM gives the same problem.

It seems to be associated with passing a reference to an array (any kind of
array) to a method expecting an object. That /should/ be OK, but it seems to
trigger this error. The same thing happens with System.identityHashCode().

(BTW, if you report this as a bug, then System.identityHashCode() might be a
better example to use, since it side-steps the potential confusion with people
thinking you might expect to see the /output/ of println() or explaining that
you don't need to use println() to "look at" a variable.)

-- chris
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jan_bar schreef:
Thanks for testing, in fact it works for me too, the sample was wrong.
Please try this:

public static void main(String args[]) {
System.out.println(args);

Object o = args;
System.out.println(o);// <- breakpoint
}

Both println's will print something on console but calling the same function
as expression doesn't work. Seems like Eclipse bug (3.1.2).

In the Variables view, arrays are printed using Arrays.toString(arr),
not with arr.toString(), because this gives uninteresting information.
Maybe this confuses you?

In the console, I get [Ljava.lang.String;@1feca64, but the Variables
view says [].

H.
- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEfrELe+7xMGD3itQRAhbUAJ9ET+lTumQ+n+f13+koJ5kVEgkU3gCeMWc/
QFNrM6o939CutzD0VKmAiik=
=PE1w
-----END PGP SIGNATURE-----
 
J

jan_bar

In the Variables view, arrays are printed using Arrays.toString(arr),
not with arr.toString(), because this gives uninteresting information.
Maybe this confuses you?

No. The problem is, that when you use this as Expression in Eclipse, you
will get InvalidTypeException. It was confirmed by Chris.

Jan
 
J

jan_bar

Thanks Chris for you suggestions.

Jan

Chris Uppal said:
jan_bar said:
public static void main(String args[]) {
System.out.println(args);

Object o = args;
System.out.println(o);// <- breakpoint
}

Both println's will print something on console but calling the same
function as expression doesn't work. Seems like Eclipse bug (3.1.2).

Yes, I see the same error (my Eclipse is at 1.3.1). Eclipse bug or JVM
bug.
Recompiling for 1.4, and running on a 1.4.2 JVM gives the same problem.

It seems to be associated with passing a reference to an array (any kind
of
array) to a method expecting an object. That /should/ be OK, but it seems
to
trigger this error. The same thing happens with
System.identityHashCode().

(BTW, if you report this as a bug, then System.identityHashCode() might be
a
better example to use, since it side-steps the potential confusion with
people
thinking you might expect to see the /output/ of println() or explaining
that
you don't need to use println() to "look at" a variable.)

-- chris
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

jan_bar schreef:
No. The problem is, that when you use this as Expression in Eclipse, you
will get InvalidTypeException. It was confirmed by Chris.

Well, in
Eclipse SDK

Version: 3.2.0
Build id: I20051215-1506

with Java 1.5 everything seems to be fine... Maybe you should switch to
a milestone release.

H.
- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEftE3e+7xMGD3itQRApD8AJ9QlmfLKmcWx58iNQ98Xax7KRoWJACfY6FW
NiF1inP+Ew1IEP+isdQKzTo=
=xkQc
-----END PGP SIGNATURE-----
 
O

Oliver Wong

Chris Uppal said:
jan_bar said:
public static void main(String args[]) {
System.out.println(args);

Object o = args;
System.out.println(o);// <- breakpoint
}

Both println's will print something on console but calling the same
function as expression doesn't work. Seems like Eclipse bug (3.1.2).

Yes, I see the same error (my Eclipse is at 1.3.1). Eclipse bug or JVM
bug.
Recompiling for 1.4, and running on a 1.4.2 JVM gives the same problem.

It works for me. Again, it reports that the value of the expression is
(void), and as a side effect, prints "[Ljava.lang.String;@145e044" to the
console. I'm using Eclipse 3.2.0 I20060519-1206. It's one of the release
candidates (RC4? RC5?). JVM, for what it's worth, is 1.5.0_06-b05.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top