Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343697 - ArrayList.size context menu is misleading
Summary: ArrayList.size context menu is misleading
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-24 05:06 EDT by Jonathan Camilleri CLA
Modified: 2011-05-05 05:11 EDT (History)
2 users (show)

See Also:


Attachments
Screenshot (20.68 KB, image/jpeg)
2011-04-24 05:08 EDT, Jonathan Camilleri CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Camilleri CLA 2011-04-24 05:06:17 EDT
Build Identifier: M20110210-1200

I'm trying to debug a grammatical issue with the output value of toString(), however, it seems that the output (from Apache log4j) indicates that Player.toString() will return the following value, which is grammatically incorrect, since I want to add a ',' only in between one member and the other, whilst the last member of the ArrayList is still not reached.

However, it is noted that while in 'Debug' mode, I cannot directly review the value of the variables 'i'- from the Outline (or other window).

It is also noted that the value of size (see eclipse - scr.jpg attached) is misleading considering the the current value of CardsHeld.size() is 2, and, somehow empty place holders are showing up.

117563 [main] DEBUG poker.Poker  - Player One holds the following cards: TWO of CLUBS, FOUR of HEARTS, .

...
public String toString() {
	
	String _cardsHeld = ""; 
	BasicConfigurator.configure();
	//TODO: DEBUG grammatical error i.e. comma separating each card and "." for the last card, the last rule is not working as expected.
	for (int i = 0; i < CardsHeld.size(); i++) {
		if (i < CardsHeld.size()) 	
			{_cardsHeld += CardsHeld.get(i).toString() + ", ";}
		else if (i == CardsHeld.size())
			{_cardsHeld += CardsHeld.get(i).toString() + ".";}
	}
	
	return (name + " holds the following cards: " + _cardsHeld) ;
}
...

Reproducible: Didn't try
Comment 1 Jonathan Camilleri CLA 2011-04-24 05:08:57 EDT
Created attachment 193964 [details]
Screenshot
Comment 2 Chris West (Faux) CLA 2011-04-24 11:05:14 EDT
You're after the "show logical structure" button at the top of the Variables view.  Window -> show view -> variables, and depress the button.  (It's a little yellow arrow pointing to a blue tree with red boxes off it.  I can't find it in the preferences at all.)  It, surprisingly, makes Eclipse show the logical structure of the container, what you expect, instead of the actual underlying data.

e.g. http://faux.uwcs.co.uk/linkedlistdebug.png
Comment 3 Dani Megert CLA 2011-04-26 03:43:11 EDT
The debugger shows the real object. In the case of an array it shows all allocated slots (capacity). Also note that the help/context info is provided by the JRE you are using and not Eclipse.
Comment 4 Jonathan Camilleri CLA 2011-04-26 03:51:58 EDT
(In reply to comment #3)
> The debugger shows the real object. In the case of an array it shows all
> allocated slots (capacity). Also note that the help/context info is provided by
> the JRE you are using and not Eclipse.
Thanks
Comment 5 Jonathan Camilleri CLA 2011-04-26 03:52:15 EDT
(In reply to comment #2)
> You're after the "show logical structure" button at the top of the Variables
> view.  Window -> show view -> variables, and depress the button.  (It's a
> little yellow arrow pointing to a blue tree with red boxes off it.  I can't
> find it in the preferences at all.)  It, surprisingly, makes Eclipse show the
> logical structure of the container, what you expect, instead of the actual
> underlying data.
> 
> e.g. http://faux.uwcs.co.uk/linkedlistdebug.png
Thanks
Comment 6 Jonathan Camilleri CLA 2011-04-27 03:44:19 EDT

(In reply to comment #3)
> The debugger shows the real object. In the case of an array it shows all
> allocated slots (capacity). Also note that the help/context info is provided by
> the JRE you are using and not Eclipse.

"There is an important distinction between the capacity of an array list and the size of an array.

If you allocate an array with 100 entries, then the array has 100 slots, ready for use. 

An arraylist with a capacity of 100 elements has the potential of holding 100 elements (and, in fact, more than 100, at the cost of additional reallocations; but at the beginning, even after its initial construction, an arraylist holds no elements at all."

Quoted from Core Java Fundamentals Volume 1 (http://www.amazon.com/Core-Java-TM-I-Fundamentals-8th/dp/0132354764).
Comment 7 Jonathan Camilleri CLA 2011-04-27 03:44:48 EDT
Page 205.