property accessors revisited

Just to drive the point home, guess what just brought down our latest release. A combination of Property accessor logic and not knowing what the underlying framework does, or does not do.

Now I believe this to be fairly harmless getter, we keep a history of dates and the current date is the first on in the list (its sorted). So if there is a list, and it has an entry, get the first one otherwise return null. Simple

 public Date getCurrentDate(){
     if(present(DATE_COLLECTION){
        Collection dates= get(DATE_COLLECTION);
        return dates.size() == 0?null:(Date)dates.get(0);
    }
  return null;  
}

The problem is only that when checking if we have a list,  it turns out the underlying framework hides the collection away in a hashmap. As a result in some instances the hashmap is touched by infrastructure code which adds a null to it, thus a check to make sure the returned collection is not null need to be in place.

There are three points here

  • Dont put frickin’ logic in proerty accessors
  • Know thy framwework, inside out especially if its hand rolled. You will not get maqilinglists with answers
  • There are good frameworks out there, so If you handroll your framework, make sure it doens’t do stupid things.

//End rant

Advertisements



    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s



%d bloggers like this: