Today's code snippet come to us from Carl Cerecke. Carl is currently deep within the bowels of a large government application trying to complete a minor defect fix. This application is used throughout the country of New Zealand by the front line staff dealing with a sizeable percentage of the citizens. Carl knows a couple of these front line staff personally and they hate the software. Carl writes, "I work for the large international software house that has the support and maintenance contract on this impenetrable piece of enterprisey spaghetti code."

Carl continues, "here's a piece of code that has nothing to do with the defect I'm trying to fix. At least I don't think it does. It did, however, jump out at me while scrolling through the file as an exemplar examplar of the sort of code littered around the project. I had to use a pen and paper to work out exactly what conditions the setDirty(true) call was made. It was no real surprise that the if statements can be replaced entirely by a much more understandable one-liner."

    Set the value of the isRecordLocked attribute.
    @param newValue is the new isRecordLocked value.
public void setIsRecordLocked(Boolean newValue) {
    // Update state if required.
    if (isRecordLocked != null) {
        if (newValue == null || !isRecordLocked.equals(newValue)) {
    else if (newValue != null) {

    // Change the value.
    isRecordLocked = newValue;

Moral of the story? Do not try to use this code as a pick up line.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!