Errors about labels out of bounds upon opening a file with fewer headers/labels

Issue #341 closed
Robert Leach created an issue

USE CASE: WHAT DO YOU WANT TO DO?

Open a second file with fewer labels(/headers?) and not get errors.

STEPS TO REPRODUCE AN ISSUE (OR TRIGGER A NEW FEATURE)

  1. Open test_dataset3.txt
  2. Open small_133x133.cdt
  3. Hover the cursor over the matrix

CURRENT BEHAVIOR

Continuous errors scroll across the console. E.g.:

error: tried to retrieve header for  index 390 but max is 133
null
null
error: tried to retrieve header for  index 390 but max is 133
null
null
error: tried to retrieve header for  index 390 but max is 133
null
null
error: tried to retrieve header for  index 390 but max is 133
null
null
paintComposite.  Temporary band change? [no]
Saving window dimensions & position.

EXPECTED BEHAVIOR

No console errors.

DEVELOPERS ONLY SECTION

SUGGESTED CHANGE (Pseudocode optional)

Reset the max when a new file is opened.

FILES AFFECTED (where the changes will be implemented) - developers only

unknown

LEVEL OF EFFORT - developers only

minor

COMMENTS

Comments (11)

  1. Robert Leach reporter

    Turns out that there's a TODO that, if it had been done, would have prevented this issue:

            /* TODO: Check whether any of the string data has changed if the
             * user changes labels OR when such a change is made, set the
             * lastDrawn* etc. variables to initial values again. */
    
  2. Robert Leach reporter

    Resolved issue 341. Label index is now checked against the size of the array before accessing it.

    When the user opened a file with fewer labels than the previously opened file and the longest label in the previous file was at an index out of range from the previous file, a null pointer exception was thrown. I added a check of the index and the string at that index to make sure things haven't changed before relying on that index.

    Funnily enough, there was a TODO in the code to implement this check and re-initialize the appropriate values.

    → <<cset 6a3d286fbc23>>

  3. Robert Leach reporter

    Resolved issue 341. Label index is now checked against the size of the array before accessing it.

    When the user opened a file with fewer labels than the previously opened file and the longest label in the previous file was at an index out of range from the previous file, a null pointer exception was thrown. I added a check of the index and the string at that index to make sure things haven't changed before relying on that index.

    Funnily enough, there was a TODO in the code to implement this check and re-initialize the appropriate values.

    → <<cset 6a3d286fbc23>>

  4. Robert Leach reporter
    • removed milestone

    Removing milestone: Coding Convention Adherence (automated comment)

  5. Log in to comment