Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display array length in Eclipse debugger?

When debugging a java program in Eclipse, I can see (e.g. in the Variables view) the content of an arbitrary array, see the picture bellow (with the ByteArrayInputStream.buf field).

Eclipse Variables view with an array

But I cannot find the array length field anywhere. Is there a way to show the length of an array in Eclipse debugger? How can I do it?

like image 642
dedek Avatar asked Sep 16 '15 07:09

dedek


1 Answers

You can use the "Expressions" view and evaluate the length member:

Expression tab screenshot

Keep in mind that the last index is one less than the length!

While this works for public array members, it seems that an explicit cast is required for protected members. Consider the following code:

...
ByteArrayInputStream is = new ByteArrayInputStream(new byte[1769]);
...

Now, when evaluating is.buf, the Expressions view shows a dump of the array as shown in the question, but evaluating is.buf.length fails with <error(s)_during_the_evaluation>. If we add an explicit cast to ByteArrayInputStream, the evaluation works:

enter image description here

like image 136
Andreas Fester Avatar answered Oct 11 '22 22:10

Andreas Fester