Issue 79482 - Table.InsertCellAt loops on a changing collection and throws an exception. Moreover it doesn't respect the zero based index
Summary: Table.InsertCellAt loops on a changing collection and throws an exception. Mo...
Status: CONFIRMED
Alias: None
Product: Calc
Classification: Application
Component: code (show other issues)
Version: OOo 2.2.1 RC3
Hardware: All All
: P3 Trivial (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-11 14:51 UTC by linox
Modified: 2013-03-11 15:04 UTC (History)
1 user (show)

See Also:
Issue Type: PATCH
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Patch (15.37 KB, text/plain)
2007-07-13 10:02 UTC, linox
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description linox 2007-07-11 14:51:47 UTC
In AODL (cvs path: odftoolkit/aodl/AODL) there's an error:
in Document\Content\Tables\Table.cs line 222

This uses an enumerator on a changing collection (it is wrong and it throws an
exception)

The old line: 
for(int i=0; i < rowIndex-this.RowCollection.Count; i++)

must be changed to:
int cnt = this.RowCollection.Count;
for(int i=0; i < rowIndex-cnt; i++)


BTW: how can I checkin to CVS without reporting the bug here?
What user/password should I use?
Thank you
Comment 1 linox 2007-07-11 14:55:45 UTC
Better explained the issue
Comment 2 linox 2007-07-12 08:08:32 UTC
I found that even with the fix the method doesn't respect the "zero based index"
param spec.

Table.InsertCellAt(0,0) should insert at "A1"
This is a more complete and clean patch:

diff -w -b -i -r1.3 Table.cs
210,211c210,211
< 		/// Inserts the cell at the specified position. Both indexes are zero
< 		/// based indexes!
---
> 		/// Inserts the cell at the specified position. 
> 		/// Both indexes are zero based indexes!
220,223c220,221
< 			if(this.RowCollection.Count <= rowIndex)
< 			{
< 				for(int i=0; i < rowIndex-this.RowCollection.Count; i++)
< 					this.RowCollection.Add(new Row(this,
"row"+this.RowCollection.Count.ToString()+i.ToString()));
---
>             for (int i = this.RowCollection.Count; i <= rowIndex; i++)
>                 this.RowCollection.Add(new Row(this, "row" + i.ToString()));
225,239c223,224
< 				this.RowCollection[rowIndex-1].InsertCellAt(columnIndex-1, cell);
< 				cell.Row				= this.RowCollection[rowIndex-1];
< 			}
< 			else if(this.RowCollection.Count+1 == rowIndex)
< 			{
< 				Row row					= new Row(this,
this.RowCollection[this.RowCollection.Count-1].StyleName);
< 				row.InsertCellAt(columnIndex-1, cell);
< 				cell.Row				= row;
< 				this.RowCollection.Add(row);
< 			}
< 			else
< 			{
< 				this.RowCollection[rowIndex-1].InsertCellAt(columnIndex-1, cell);
< 				cell.Row				= this.RowCollection[rowIndex-1];
< 			}
---
> 			this.RowCollection[rowIndex].InsertCellAt(columnIndex, cell);
> 			cell.Row = this.RowCollection[rowIndex];

and

diff -w -b -i -r1.2 Row.cs
174,177c174
< 			if(this.CellCollection.Count <= position)
< 			{
< 				//3 - 5 = 6, 5 - 5 = 6
< 				for(int i=0; i < position-this.CellCollection.Count; i++)
---
>             for (int i = this.CellCollection.Count; i < position; i++)
179,186c176
< 				this.CellCollection.Add(cell);
< 			}
< 			else if(this.CellCollection.Count+1 == position)
< 			{
< 				this.CellCollection.Add(cell);
< 			}
< 			else
< 			{
---
> 
189d178
< 		}
Comment 3 linox 2007-07-13 10:02:05 UTC
Created attachment 46745 [details]
Patch
Comment 4 linox 2007-07-13 10:03:26 UTC
Issue fixed
Comment 5 ooo 2007-07-13 15:35:26 UTC
Not quite fixed.. you just made a patch available.
Please _attach_ the patch file instead of pasting it as a comment where it may
get reformatted at any browser's will and may not apply afterwards.

Also, spreadsheet is the wrong component here, it should be odftoolkit instead,
but for some mysterious reasons isn't available in the list box now that
spreadsheet is assigned?!?

Reassigning to the odftoolkit project lead for further processing.
Comment 6 ooo 2007-07-13 15:36:12 UTC
Reopening.
Comment 7 linox 2007-07-13 15:41:51 UTC
I tried to assign it to component odftoolkit (but it was missing since the
beginning)

(and I already provided the patch as an attachment)
Comment 8 Dieter.Loeschky 2008-10-21 10:45:21 UTC
DL->LarsBehr: Hi Lars, could you please takeover this issue?
Comment 9 Rob Weir 2013-03-11 15:04:16 UTC
I'm adding this comment to all open issues with Issue Type == PATCH.  We have 220 such issues, many of them quite old.  I apologize for that.  

We need your help in prioritizing which patches should be integrated into our next release, Apache OpenOffice 4.0.

If you have submitted a patch and think it is applicable for AOO 4.0, please respond with a comment to let us know.

On the other hand, if the patch is no longer relevant, please let us know that as well.

If you have any general questions or want to discuss this further, please send a note to our dev mailing list:  dev@openoffice.apache.org

Thanks!

-Rob