Monday, September 24, 2012

OptionalDataException while reading JMS message

We've been dealing with another bug in JMS code. The symptom was blocked queues and the following exception:

javax.jms.JMSException: getObject
          [...] 
Caused by: java.io.OptionalDataException
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1325)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
      at java.util.HashMap.readObject(HashMap.java:1066)

In trying to reproduce people in the team introduced a non-serializable object, but he got an exception at sending the message (Caused by: javax.jms.JMSException: setObject [...] java.io.NotSerializableException). In a similar way, trying to send an int, he got a NotSerializableException. And trying to send some class and then changing the serialVersionUID, he got an error at receiving, but a different error (java.io.InvalidClassException).

Everything in Internet pointed to a thread-unsafe error, so we looked at the code and found this


        mensaje = receptorMensaje.receive(timeOut*1000);
        [...]
        mensaje.acknowledge();


with several lines of code between the receive and the acknowledge, and without synchronization

Under very heavy load, it was easy to have a thread execute the receive, a different thread execute the receive and then the first thread acknowledge. But by then both threads have the same object and if the first thread changed its copy, the Exception would be triggered.

We extract a method this code and synchronized.

Sunday, September 23, 2012

June deficit was 8.54%

From time to time I write about politics in Spain in general and in particular Spanish deficit. Sometimes I try to do some simple estimations and comments.
More recently there has been some comments in Spain regarding the publication of regions' budget deficit up to second quarter. But I don't really understand why people insist to pay attention to quarterly data without reference to a twelve month period. Let's do the math.

First deficit: It seems that, if we leave out the help to the financial institutions, deficit in 1Q2012 and 2Q12 has been 39815 million euro. Deficit in 3Q2011 and 4Q2011 was:-16.616-34.054 = 50670 million euro. So, twelve month period ending on June 30th: 90485 million euro.
Then GDP: Acording to INE, GDP for 3Q2011,4Q2011,1Q2012,2Q2012: 255367 + 275032 + 259198 + 269739: Total: 1059336 million euro.
Now let's divide both. 90485/1059336.

Deficit in terms of GDP at June 30th using public data: 8,54%

Daniel Lacalle says it's 8,56%. Surely I missed something. But not too much.



Saturday, September 22, 2012

Weird IE9 bug

This last two weeks I have dealt with a weird bug in IE9.

  • The problem appeared in a legacy web application. 
  • The issue reported by the user was a combo that didn't drop down. 
  • The problem appeared in different pages, but only for some combination of values.
  • The issue appeared after installing IE9 from IE7 in a Windows Vista. 
  • The user could reproduce the issue (for a certain combination of values).
  • We (both devs and ops) couldn't reproduce in a standard machine even tough at work final users deal with a very standard machine (machine setups are pretty standarized at work). 
  • When we finally were able to reproduce in a standard machine, it only failed the first time a user logged in (second time, or even IE close rendered the bug irreproducible).
  • We finally were able to pinpoint the problem to a very large option (as in 400 characters).
  • And now I've been able to reproduce it with a reduced version of the page even in my setup (Vista64+IE9). See the gist. Save to a file, launch it with IE9 and try to change the option.

We trimmed down to 200 chars (I guess even 150 chars wouldn't be viewable).

UPDATE (2012-09-30): Tested on IE10 in Windows8 and seems to work fine.

Thursday, September 20, 2012

Techzing wives

I tend to listen Techzing podcast. It's a podcast about very different topics, recorded by two geeks, (or developers, and entrepeneurs). I don't remember when I started listening them. I do remember I started because I wanted to practice English and it was great (Justin is an Englishman and Jason is American). Soon I forgot why: they were great by themselves. The topics are very diverse from Technology, Entrepenurship, Politics (Loom and Gloom Report), Education, Genetics...

I listen them while commuting, and I was a couple of months behind. However, I just listened episode 200: techzing wives.

And it's simply the best. I couldn't help but laugh in many different parts of the episode.

I guess that episode is not very interesting for a newcomer. But I'm sure that for most of their regular listeners it has been a great experience to listen to our own wives in the voices of three complete estrangers.

Friday, September 14, 2012

My first Chrome extension(II)

In last post I wrote why. In this post I want to explain how I wrote my first chrome extension.

First. The Chrome Extensions developer's documentation is quite good.

Second. A chrome extension is a zip of a folder with an crx extension instead. The folder has to have a particular file called manifest.json. It tells the extension name and the permissions asked. It also points to the main file. Pretty standard in my case.

The main file, in my case was called background.js. You should read the documentation to know more about background pages and so on.

In my case, I attach an event listener to the click of the extension button (browserAction.onclick). The listener gets the url of the current tab, process that url, encode it, get a Google url redirection from it, and ask for it.

chrome.browserAction.onClicked.addListener(function(tab) {
  var currentTab=tab.url;
  var processedURL=processURL(currentTab);
  var encodedURL=encodeURIComponent(processedURL);
  var newUrl="http://www.google.es/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&sqi=2&url="+encodedURL;
  chrome.tabs.update(tab.id, {url:newUrl});

});


The processing of the URL do a bit of tweaking for some specific servers. Pretty uninteresting.

My first Chrome extension(I)

This afternoon I was preparing an interview I expect to have next week, and came to an interesting page with information about job selection process and companies inside information. However, after surfing a bit, the inevitable, "become a registered member" started to bug me.

And I got tired.

And I remembered FT similar "become a registered" and WSJ "first-paragraph-only". Lots of sites show you the page when you come from Google, but ask you to register if you start to surf (or just come from a different page). Completely understandable, but not very pleasant.

So I asked myself if it would be too complicated to build an extension for Google Chrome, that when you are at a page and asks to register, you ask google to get redirected to that page. It seems it's not. I started poking at 19:00 (local development folder creation time was 19:07) and ended building it at 20:30 (icon included). It's pretty basic, but it makes a bit of tweaking with FT and WSJ URLs because just coming from Google was not enough. And now it works, with glassdoor, FT, and WSJ.

Great. I learnt and I have something interesting to show.

In the future.

Maybe showing I'm willing to "hack" a paywall is not something I should be publishing when interviewing for a financial information company. Or maybe yes. Anyway: this is me.

Next post. How I did it.

Monday, September 10, 2012

Tuesday, September 4, 2012

Calisthenics

I didn't know about object calisthenics. They are a set of rules to help develop better:

1. One level of indentation per method
2. Don’t use the ELSE keyword 
3. Wrap all primitives and Strings4. First class collections
5. One dot per line
6. Don’t abbreviate
7. Keep all entities small
8. No classes with more than two instance variables
9. No getters/setters/properties
Some of them are a must, with some others I have some doubts. But the point 2 is so intriguing I have to test it.

Sunday, September 2, 2012

No more applets

For more than three years I've been managing certificate-based digital signature applications.

 One of the main source of pain always was and is generating the signature on the user browser. As it needs access to the user's keystore, the browser alone didn't have access to it, and was needed some kind of component (either ActiveX, usually a Java applet). The deployment of the component and the debugging of different OS/browser/Java version configurations tends to be time consuming.

I even was trying to create my own version of component to help stop reinventing the wheel.

For all the time lost, the existence of a group in the W3C to incorporate crypto to the browser is GREAT NEWS.