A collection of thoughts, ideas and rants inspired by my career in the fintech and banking industry.

Can not execute Sonar: Missing column: period in ALERTS

I recently encountered the following error in Sonar 3.5

[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar
(default-cli) on project smartfx: Can not execute Sonar: Missing column:period in DB.ALERTS -> [Help 1]  
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal
org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project	myproject: 
Can not execute Sonar  
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:	203)  
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:	148)  
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:	140)  
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)  

A quick check of the database revealed that the ALERTS table does indeed contain a column named ‘period’.

[Read More]
Sonar 

hg clone fails with 255 error

I recently encountered an issue with cloning a Mercurial repository where it would fail with an obtuse error stating that “[command returned code 255 Mon Mar 25 11:39:55 2013]”. My initial Googling implied that this was caused by a server timeout but the problem persisted even after increasing the timeout on our Apache web server.

The clone was always failing on one particular file - a 600Mb binary. (Don’t ask…)

[Read More]

The Guild

Troy Hunt’s Ghost Who Codes ignited something inside me. Initially I was a little insulted because I don’t have much of an online presence apart from my blog and my Twitter account. There are many reasons for this but in the end it doesn’t matter.

You see, as much as I respect Troy, I think he’s missing the point.

The best developers rarely apply for advertised jobs. They’re hired through their network and are never on the market. They’re members of The Guild; they’re the fat guys who know C++.

[Read More]

Apache commons for readability

There are many short methods in the Apache Commons libraries that seem like overkill at first glance, however, their purpose becomes more apparent when you examine the effect that these methods have on the readability of the caller.

I see a lot of code that does stuff like this:

if( s == null || "".equals(s.trim())) {  
	// Do something  
}  

which could be re-written as

if( StringUtils.isBlank(s)) {  
	// Do something  
}  

Personally, I find it much easier to understand the intent of the second version.

[Read More]

SonarException: The project is already been analysing.

I was getting this error when running a Sonar analysis recently.

This was caused by the Jenkins/Sonar process getting killed while the project analysis is underway. Sonar now uses a database semaphore to prevent multiple builds running at the same time, but if the job gets terminated then the semaphores don’t get cleaned up.

To fix the problem: Log into the database and delete any rows in the ‘semaphores’ table.

[Read More]
Sonar 

How to show which .hgrc Mercurial is using

Mercurial loads a bunch of different configuration files and overlays their values on top of each other. The hgrc man page shows the order in which these files are loaded.

I encountered an issue recently where I knew that hg was using an erroneous setting but I had no idea where the setting was coming from.

The magic answer is

hg --debug showconfig  

This will output all the current settings, along with the name of the file that it got each setting from. Very useful indeed.

[Read More]

How to take local in Mercurial without a merge conflict

When there’s a merge conflict in Mercurial, TortoiseHG will give you the option to ’take local’ or ’take other’ in addition to resolving the conflict.

However, sometimes you may want to ’take local’ or ’take other’ when there’s no merge conflict.

To take local:

hg merge --tool internal:local <rev>  

To take other:

hg merge --tool internal:other <rev>  

Broken Generics

Given the following code

Map<String, String> map = new HashMap<String, String>();  
map.put("123", "value");

Integer key = Integer.valueOf(123);  
String actual = map.get(key);  

What is the value of “actual”?

  1. Compilation error - key should be a String
  2. “value”
  3. null

Answer: null

This blew me away. The whole point of type-safe collections was supposed to provide compile-time checking. However, the only generics method on the Map class is put(K, V). So calling get(Object) doesn’t cause a compilation error, but merely returns null.

[Read More]
Java 

Slow Mercurial clone

I recently set up a Mercurial server (Windows, Apache, ActiveDirectory and hgweb.wsgi). However, cloning our 1Gb repository took an hour or more and often failed.

The only information in the Apache log was

mod_wsgi (pid=1234: Exception occurred processing WSGI script
'C:/hg/hgweb/hgweb.wsgi'  
IOError: failed to write data  

The solution was to disable compression by adding the following lines to hgweb.config

[server]  
preferuncompressed = true  

By default, Mercurial will compress everything before sending it down the pipe. This makes sense if you have a powerful server and a slow network, but the opposite was true for us - Mercurial’s hosted on an old dual-core Windows VM connected to a 1Gb corporate LAN.

[Read More]

Error creating logs directory in Apache Tomcat

java.util.logging.ErrorManager: 4: Unable to create [c:pache-tomcat-7.0.30 -Dcatalina.home=c:pache-tomcat-7.0.30\logs\]

I was getting this error recently, and found that it was caused by having a trailing backslash on my CATALINA_HOME variable.

i.e.
Incorrect:

set CATALINA_HOME=c:pache-tomcat-7.0.30\

Correct:

set CATALINA_HOME=c:pache-tomcat-7.0.30
Tomcat