You are viewing stevebosman

   Journal    Friends    Archive    Profile    Memories
  'Twas Brillig* | Flickr | MSN Space |

Il Brilgue

Jan. 25th, 2008 02:44 pm On Laziness

A tendency exists to disguise laziness in the garb of simplicity. "A complete undo system adds too much complexity, so let's just throw up a confirmation dialog."

-- Alan Holub


Powered by ScribeFire.

Leave a comment

Nov. 7th, 2007 08:52 am Who wrote this crap?

Quote of the day:

"There's a knee-jerk predisposition to look at code you didn't write, and for various reasons large and small, proclaim it absolute crap."

Leave a comment

Nov. 2nd, 2007 09:04 am Technical Debt


Steve McConnell on Technical Debt


Powered by ScribeFire.

Leave a comment

Sep. 12th, 2007 02:39 pm The specified call count is not a number: null

Problem
After several minutes logged into our application some IE users (firefox users don't seem to get this problem) get the javascript alert "The specified call count is not a number: null".

Cause
I tracked down the alert as coming from the Batch class of DWR. We use DWR to maintain a status icon

function checkStatus() {
    StatusService.getStatus(
        <c:out value="${appId}"/>, {
            async:true,
            callback:function(obj) {
                // populate div based on status result
                // SNIP!
            }
        }
    );
    top.setTimeout("checkStatus();", 5000);
}
checkStatus();

A colleague and I used packetyzer to examine the packets sent and received on a simulated network (using The Cloud) and discovered that with IE the request is sent in two packets (the first packet contains just the header and the second the contents), unfortunately the sending of the second packet sometimes fails (it seems to be related to when a second process is transferring a large quantity of data) and the port the request is using is blocked for 10 minutes (to the second). After 10 minutes we receive an error response containing the message in the subject (it makes sense since callCount is defined in the request contents and since it hasn't been received it defaults to null).

Solution
A response to an email to the dwr mailing list helped me formulate a solution
1. Add a custom timeout (in milliseconds)
2. Add a custom error handler (since we are dealing with a status icon - the alerts are more annoying to our users than the error).

giving something a bit like
function checkStatus() {
    StatusService.getStatus(
        <c:out value="${appId}"/>, {
            async:true,
            timeout:5000,
            callback:function(obj) {
                // populate div based on status result
                // SNIP!
            },
            errorHandler:function(message, ex) {
              statusDivElement = document.getElementById("status");
              statusTdElement = document.getElementById("statusTd");
              if (ex!=null) {
                statusTdElement.title = "Error: " + ex.name + ", " + ex.message;
              } else {
                statusTdElement.title = message;
              }
              statusDivElement.innerHTML = "<img src='errorImgUrl' alt='" + message + "' />";
            }
        }
    );
    top.setTimeout("checkStatus();", 5000);
}
checkStatus();

Current Mood: accomplishedaccomplished

Leave a comment

Sep. 5th, 2007 03:43 pm Derby error: "An SQL data change is not permitted for a read-only connection, user or database."

Problem
Getting the following exception in a Derby database backed application.

ERROR 25502: An SQL data change is not permitted for a read-only connection, user or database.
     at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
     at org.apache.derby.impl.sql.conn.GenericAuthorizer.authorize(Unknown Source)
     at org.apache.derby.impl.sql.execute.GenericResultSetFactory.getUpdateResultSet(Unknown Source)
     at org.apache.derby.exe.ac15061736x0114xd5bcxb977xffffd8f7e81db0.fillResultSet(Unknown Source)
     at org.apache.derby.exe.ac15061736x0114xd5bcxb977xffffd8f7e81db0.execute(Unknown Source)
     at org.apache.derby.impl.sql.GenericActivationHolder.execute(Unknown Source)
     at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
     ... 40 more

Cause

I discovered that someone had written a Dao with code like this:

      Connection connection = getConnection();

      connection.setReadOnly(true);

      ps = connection.prepareStatement(sqlQuery);
      for (int i=0; i<orderedParamsList.size(); i++) {
        ps.setObject(i+1, orderedParamsList.get(i));
      }

      rs = ps.executeQuery();

      if (rs.next()) {
        returnValue = rs.getObject(1);
      }

      ResultSetMetaData rsMeta = rs.getMetaData();
      if (rsMeta.getColumnCount() > 1 || rs.next()) {
        // if there are more than one value in result set - return null
        returnValue = null;
      }

      // rollback changes if there are any made by query
      connection.rollback();

The developer wanted the transaction to be read only (the SQL is user defined - so treated as dangerous), unfortunately the connection was not being restored to writeable at the end and the next transaction to reuse the connection fell over.

Solution
Added a connection.setReadOnly(false) call (along with the rollback) within a finally block.

Leave a comment

Jun. 12th, 2007 03:18 pm Oracle to SQL 92: NVL

Instead of NVL(foo,bar) use the following CASE WHEN foo IS NULL THEN bar ELSE foo END

Tags: ,

Current Location: Birmingham, UK
Current Mood: workingworking

Leave a comment

Apr. 30th, 2007 08:52 pm Disappearing request parameter

Not mine, but I had to fix it. The code gets a String (authenticationId) out of the request and converts it to a long:
compo = remoteServiceBd.login(Long.getLong(authenticationId), username, password);
unfortunately inside the login method authenticationId is alway null.

This is down to one of the great irritants of java, confusingly named methods in the main API. The static method Long.getLong(String) does not work in the way a casual reader might think, the static method Long.valueOf(String) should be used instead. The method Long.getLong(String) is roughly to Long.decode(System.getProperty(String)) with all the exceptions hidden (including NumberFormatException which strikes me as insane).

Tags:

Current Mood: workingworking

Leave a comment

Apr. 30th, 2007 12:05 am Bug Blogging

Ages ago (in TAOCP?) I read something suggesting that keeping a personal bug journal is a good idea, so since I've just realised I'm less likely to lose a blog than a notebook, I'm going to give it a whirl in here. Most bugs are work related - so for the most part they'll be private.

Tags:

Current Mood: workingworking

Leave a comment