Results 1 to 4 of 4
  1. #1
    Luxpsycho is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Exclamation 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
    1. I am programming for a company who are really strict about privacy and such
    2. 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:
    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...
    Steps already taken:

    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:
    When you help me, actually:
    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

  2. #2
    Luxpsycho is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default

    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 :)

  3. #3
    Luxpsycho is offline Member
    Join Date
    Jul 2010
    Posts
    4
    Rep Power
    0

    Default

    How do I delete this. Please delete. Or close.

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Closing thread. If any other mods feel that I should leave it open, feel free to open it and let me know.

Similar Threads

  1. Movie Picture Morphing
    By Mabyboi in forum Java 2D
    Replies: 1
    Last Post: 11-16-2011, 07:20 AM
  2. Replies: 2
    Last Post: 03-03-2011, 11:08 PM
  3. Derby Mystery..!!!!
    By yiantzi in forum JDBC
    Replies: 3
    Last Post: 01-24-2011, 12:59 PM
  4. Morphing
    By aRTx in forum New To Java
    Replies: 4
    Last Post: 05-05-2009, 01:01 PM
  5. Auto-complete/Auto-fix for custom statement
    By dark_cybernetics in forum Eclipse
    Replies: 0
    Last Post: 08-19-2008, 12:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •