Results 1 to 4 of 4
- 08-11-2011, 11:30 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
The Mystery of the auto-morphing variables
This is really curious, and I am not one who posts a lot. I usually debug on my own and google until a black hole forms inside my ethernet card...
I will not be able to post actual code because
- I am programming for a company who are really strict about privacy and such
- It is too big anyway (dozens of classes)
I will however give as many details as I deem useful and answer any questions I deem relevant, which in sightof my depseration will most liely be all of them.
Here we go:
I have a customised class called Period which contains two Calendars and a String containing the name (e.g. "Jul 2011" or "Week of the XXX").
A class Parameters contains information about the parameters entered by the user, among others global start and end dates and frequency (e.g. weekly). Based on that I calculate a List<Parameters> and store that in the Parametersclass as well.
Now I pass an instance of the Parameters class to a method (different class) which fills a JTable, with the number of columns based on the amount of periods.
It works, B U T . . .
Here is the thing: the start dates of each period start gradually becoming the same as the end date. Let me explain...
The table may have several hundred rows. During the evaluation of each of those I use the same instance of Parameters. Yet, after a number of rows, a few dozen, the parameters.periodslist.get(0).startDate (name made up) suddenly becomes the same as the parameters.periodslist.get(0).endDate.
Then, a few dozen rows later, same for get(1), then get(2), then get(3).
I can see the effects in the table! (results in "0%" being displayed)
I have the following outputs to be certain of this being the cause:
Steps already taken:Java Code:FIRST ROW Week of 06/06/2011: 06/06/2011 - 13/06/2011 Week of 13/06/2011: 13/06/2011 - 20/06/2011 Week of 20/06/2011: 20/06/2011 - 27/06/2011 Week of 27/06/2011: 27/06/2011 - 04/07/2011 . . //same thing for many more rows . ROW 18 Week of 06/06/2011: 13/06/2011 - 13/06/2011 Week of 13/06/2011: 13/06/2011 - 20/06/2011 Week of 20/06/2011: 20/06/2011 - 27/06/2011 Week of 27/06/2011: 27/06/2011 - 04/07/2011 . . . ROW 95 Week of 06/06/2011: 13/06/2011 - 13/06/2011 Week of 13/06/2011: 20/06/2011 - 20/06/2011 Week of 20/06/2011: 20/06/2011 - 27/06/2011 Week of 27/06/2011: 27/06/2011 - 04/07/2011 . . . //etc...
I have now explicitely set the Parameterin the method to private, replaced all access to its periods by getPeriods() and setPeriods(), where setPeriods() shows a dialog each time it is called so I could make sure it is indeed only called ONCE.
I have checked that in the whole class containing the method, no one else accesses and changes periods in any way.
I made the Calendars in Parameters (i.e. startdate and endDate) private as well. It is only ever set by the constructor, and accessed by getStart()/getEnd(). The same goes for ArrayList<Period> in the same class.
I made both Calendars and the String in Period private, writable only by the constructor. Constructor shows dialog again, to make no period is overwritten somehow (in this case 4 periods, so for dialogs).
I wrote lots of .clone()s at function calls.
Feelings:
Now:
& 
When you help me, I'll show:.gif)
When you help me, actually:.gif)
Otherwise:
Thanks a lot,
I wouldn't post if I had any more hope left than so.
Sorry for no concrete code,
please ask if obscurity.
Luxpsycho
- 08-11-2011, 12:00 PM #2
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
Resolved. Sorry.

Turns out I passed the whole period to a method at some point, must have not seen that.
Not sure what the method does yet (will check... evil method!!!) but to be sure I passed a .clone() and ... it works now :)
- 08-11-2011, 12:04 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 4
- Rep Power
- 0
How do I delete this. Please delete. Or close.
- 08-11-2011, 12:06 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Closing thread. If any other mods feel that I should leave it open, feel free to open it and let me know.
Similar Threads
-
Movie Picture Morphing
By Mabyboi in forum Java 2DReplies: 1Last Post: 11-16-2011, 06:20 AM -
Basic Loops stalling with While Statement Mystery
By gnng in forum New To JavaReplies: 2Last Post: 03-03-2011, 10:08 PM -
Derby Mystery..!!!!
By yiantzi in forum JDBCReplies: 3Last Post: 01-24-2011, 11:59 AM -
Morphing
By aRTx in forum New To JavaReplies: 4Last Post: 05-05-2009, 12:01 PM -
Auto-complete/Auto-fix for custom statement
By dark_cybernetics in forum EclipseReplies: 0Last Post: 08-19-2008, 11:19 AM


LinkBack URL
About LinkBacks

Bookmarks