Maxime was having difficulty viewing a website with the NoScript add-on installed to her web browser. It wasn't a huge surprise - some websites just don't work right with NoScript running, but it was a surprise when her browser displayed Java exceptions. Enabling JavaScript made the error page go away, but what? Lack of JavaScript causing Java exceptions!?

She viewed the page source and found that the server expects an "innerCHK" parameter, perhaps some kind of session or security token, to be passed in via URL query string. If it isn't provided, the server returns an error page displaying a java.lang.NullPointerException. Fortunately the front-end developers concocted this brillant snippet of JavaScript to resolve this issue:

// Error check
if (document.body.innerHTML.indexOf('java.lang'+'.NullPointerException') != -1){   
   if (document.location.href.indexOf('innerCHK=') == -1){    
        document.location.href = document.location.href + "&innerCHK=" + Math.random()*10000 ;
   }
}
// End of check

That only scratches the tip of the iceberg; the page is loaded with anti-patterns, reinvented wheels, spare reinvented wheels, and flat reinvented wheels, all held on with duct tape. For a taste of some bizarre string conventions and the developers' pet anti-pattern of closing scripts only to open a new one on the next line, look at how Dojo is imported. Please take note that Dojo's cookie library is imported.

<script type="text/javascript">
    if (typeof dojo== "undefined") {        
        document.writeln('<scr'+'ipt src="' + '/wps/themes/./dojo/portal_dojo/dojo/dojo.js' + '"></scr'+'ipt>');
    }
    if (typeof dijit == "undefined") {      
        document.writeln('<scr'+'ipt src="' + '/wps/themes/./dojo/portal_dojo/dijit/dijit.js' + '"></scr'+'ipt>');
    }      
 </script>     
 <script type="text/javascript">     
 dojo.require("dijit.form.Button");
 dojo.require("dojo.cookie");
 //dojo.require("dijit.form.DropDownButton");
 dojo.require("dijit.Dialog");
 dojo.require("dijit.form.TextBox");
 dojo.require("dijit.form.CheckBox");
 dojo.require("dijit.form.ComboBox");
 </script>

Some, but not all, of the CSS references are handled in this manner which I found at least three (identical) times in the source. Yet again, Dojo.cookie is imported.

<script name="DojoEnable_script" language="JavaScript">if (typeof dojo == "undefined") {
    dojo.require("dojo.cookie");
    dojo.require("dojo.parser");
    djConfig = { parseOnLoad: false, isDebug: false};
    document.write("<script src='http://www.****************.com:80/ps/PA_WPF/factory/dojo/dojo/dojo.js'> </" + "script>");
    document.write("<link rel='stylesheet' type='text/css' href='http://www.****************.com:80/ps/PA_WPF/factory/dojo/dojo/resources/dojo.css' />");
    document.write('<link rel="stylesheet" type="text/css" href="http://www.****************.com:80/ps/PA_WPF/factory/dojo/dijit/themes/tundra/tundra.css"/>');
    document.write('<link rel="stylesheet" type="text/css" href="http://www.****************.com:80/ps/PA_WPF/factory/dojo/dijit/themes/tundra/tundra_rtl.css"/>');
    dojo.addOnLoad(function() { if (!document.body.className) document.body.className = 'tundra'});
}

It was once said that if you solve a problem with regular expressions, you now have two problems. I think two is an underestimate.

var locale = 'en'.replace(/_/, '-').replace(/iw/, 'he').toLowerCase();

Remember, children, always use well-named constants! Magic numbers are bad. Except for 2008, that one is okay.

if(typeof (MONTHS_IN_YEAR) == 'undefined')
{
    MONTHS_IN_YEAR = 12;
}

if (typeof (isDisableDate) == 'undefined') {
    var isDisableDate = function (date, year, month, iday)
    {
        if(date.getFullYear() == 2008)
        {
            return true;
        }
        return false;
    }
};

No poorly-implemented application is complete without its own poorly-implemented DateTime library. There ought to be a scientific law about this.

var month=new Array(12);
month[0]="1";
month[1]="2";
month[2]="3";
month[3]="4";
month[4]="5";
month[5]="6";
month[6]="7";
month[7]="8";
month[8]="9";
month[9]="10";
month[10]="11";
month[11]="12"; 

if(typeof (MONVALUE) == 'undefined')
{
    MONVALUE = new Array
    ("Jan",
     "Feb",
     "Mar",
     "Apr",
     "May",
     "Jun",
     "Jul",
     "Aug",
     "Sep",
     "Oct",
     "Nov",
     "Dec");
}

//function convert date from str to Num
function Month2Num(month)
{
    if(month=="JAN")return "01";if(month=="FEB")return "02";if(month=="MAR")return "03";if(month=="APR")return "04";if(month=="MAY")return "05";
    if(month=="JUN")return "06";if(month=="JUL")return "07";if(month=="AUG")return "08";if(month=="SEP")return "09";if(month=="OCT")return "10";
    if(month=="NOV")return "11";if(month=="DEC")return "12";
}

There are a number of (often duplicate) CSS styles defined, such as this not very blue style.

div.wpfThemeBlueBackgroundPanelTable  
{ 
    background: #F6F9FC; 
    padding: 10px; 
} 
/*---- Blue panel ----*/ 
table.wpfThemeBlueBackgroundPanelTable  
{ 
    background: #F6F9FC; 
    padding: 10px; 
} 

Next up are two identical arrays, only one of which is ever used.

var arr_location_001 = new Array();
var arr_location_002 = new Array();

arr_location_001['AU'] = {value:'AU', title:'australia', text:'Australia'};
arr_location_002['0'] = {value:'AU', title:'australia', text:'Australia'};

arr_location_001['CA'] = {value:'CA', title:'canada', text:'Canada'};
arr_location_002['1'] = {value:'CA', title:'canada', text:'Canada'};

arr_location_001['CN'] = {value:'CN', title:'china', text:'China'};
arr_location_002['2'] = {value:'CN', title:'china', text:'China'};

arr_location_001['FR'] = {value:'FR', title:'france', text:'France'};
arr_location_002['3'] = {value:'FR', title:'france', text:'France'};

arr_location_001['HK'] = {value:'HK', title:'hong_kong', text:'Hong Kong'};
arr_location_002['4'] = {value:'HK', title:'hong_kong', text:'Hong Kong'};

/*  snip many, many lines of similar code */

Here's a nice little script which escaped a lot of things, including its own script tags! Bonus points if the developer wrote it while tied up in a straitjacket and locked in a coffin full of scorpions suspended over the Hudson river by a helicopter. (Actually, that might be the sanest explanation for a lot of this code.)

<SPAN name="onloadScript"><input type="hidden">function onSelectInfo(calendar, date, elem_date) { 
    elem_date = document.getElementById(&quot;Day_NArr&quot;);       
    elem_mon_year = document.getElementById(&quot;Month_NArr&quot;); 
    hidden_elem = document.getElementById(&quot;temp_date_NArr&quot;); 
    doOnSelect(calendar, date, elem_date, elem_mon_year, hidden_elem); 
} 

Calendar.setup( 
    { 
        inputField : &quot;temp_date_NArr&quot;,// ID of the input field 
        ifFormat : &quot;%b, %e, %Y&quot;, 
        onSelect: onSelectInfo, 
        range : [currentYear, nextYear], 
        dateStatusFunc : dateStatusHandler, 
        button : &quot;cal_dep&quot; // ID of the button 

    } 
); 

var _InfoVerAccurateFunc = clone(accurateDate); 
initializeDate(new Array('Month_NArr', 'Day_NArr'), _InfoVerAccurateFunc);">
<script type="text/javascript">

Remember all the dojo.cookie imports earlier on? Someone made sure to include a library function for reading cookies. Still, someone else found it necessary to write copy-paste from the Internet a Get_Cookie function, not once, but four times throughout the page source!

function Get_Cookie(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false;

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split( '=' );


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if ( a_temp_cookie.length > 1 ) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}

I think the software development method used by this team was a new-fangled system called "Mash the CTRL-C and CTRL-V keys!!!!!!11!!!!11!11" It's sure to overtake Agile in the coming years.

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