Eclipse loading problem : XPCOM error

November 3, 2008

If you are an eclipse user you may have come across this error atleast once in you lifetime. Sometimes this error shown as a message “Widget disposed too early” or something like that. To be more precise when starting eclipse it just hands on a small blank dialog kind of form after specifying the workspace. You cannot close or exit from this form. It just hangs.

This happens mostly in linux. I experienced this in ubuntu hardy with Ganymede mostly. If this happenes first thing you should do it to verify the problem. Just check the log for the workspace to see what the exception thrown before eclipse hanged. For example in our case it will be something like this.

Exception in thread “Thread-1” org.eclipse.

swt.SWTError: XPCOM error -2147467262
at org.eclipse.swt.browser.Mozilla.error(
at org.eclipse.swt.browser.Mozilla.setText(
at org.eclipse.swt.browser.Browser.setText(
at org.eclipse.jdt.internal.ui.infoviews.JavadocView.setInput(
at org.eclipse.jdt.internal.ui.infoviews.JavadocView.refresh(
at org.eclipse.jdt.internal.ui.infoviews.JavadocView.setBackground(
at org.eclipse.jdt.internal.ui.infoviews.AbstractInfoView.inititalizeColors(
at org.eclipse.jdt.internal.ui.infoviews.AbstractInfoView.createPartControl(
at org.eclipse.ui.internal.ViewReference.createPartHelper(
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.j……


Now for the solution.

Well the solution is a bit murkey. I came across the worst path of solving the problem with the only solution available. Eclipse uses XUL (spelled “zool”) for its GUI rendering when in linux. This is kind of weird because the actually reason i figured out is that it uses the platform current browser to do that for him. This in the case of linux where the default browser is most of the time is Mozilla Firefox, eclipse uses the functionalities of firefox to render its GUI. If in the case of windows it uses IE as I can remember. This is why the above exception contains the words like “browser” “mozilla” etc.

Anyway the problem occures due to a simple reason, the firefox browser does the rendering using the xulrunner. There is a default xulrunner when firefox is installed and this version is not updated enough for eclipse. Thus it cannot render the UI parts and the UI widgets are disposed not being able to be created correctly. So the easy solution is to update the xulrunner.

You can do a simple

$apt-get update xulrunner or $apt-get install xulrunner

Works most of the time. But sometimes its best to do a system wide upgrade using

$apt-get upgrade

because there is a version firefox which xulrunner also supports, and if the firefox is old (or in 3.0beta for eaxmple), the xulrunner will not get updated properly.

So after that the eclipse should work fine. But mind you, you might want to start on a fresh workspace anyway.

But i have seem in some instances where eclipse can start on a already created (and previously worked) workspaces. Yeah i know, WIERD!!!

Well In my case this worked great on eclipse, but with a hitch. The firefox was giving trouble now. The address bar not working properly, icons in the title bar disabled, No history or bookmarks shown etc. It looked like the upgrade messed up the firefox.

With a little bit of searching I found that this can happen if the firefox profile gets corrupted. For those of you who does not know what a firefox profile is, its just a simple profiles created by the firefox to keep track of each and every uses preferences/history/bookmarks/etc etc.

So all you have to do is to create a new firefox profile abadoning the one you already have. Google for how to create a new profile. For those of who wants to keep the old one all they have to do is to go and rename the “localstore.rdf” file to say “localstore.rdf.tmp” and restart the browser. (This file is normally located in “~/.mozilla/firefox/<somefolder_for_the_profile>/localstore.rdf”).

localstore.rdf is the file where most of the settings of the profile are declared. When this file is missing the browser automatically resets the settings for the browser. And you will see that the buttons and icons etc will start working normally again ūüôā

but make sure u rename the “localstore.rdf.tmp” back to “localstore.rdf” after the browser resets the settings. Because if not eclipse again will start giving problems and this time it will not be specific on what the problem is. It will not even mention that the problem is with the profile of the browser. It will just not behavie as you expect and make you think there is something wrong in you code (because most of the time it doesn’t throw an exception also). In my case this happened to me. Where i was not able to add a dynamic project to the tomcat server as the runtime environment. We can add the dynamic projects to run with the tomcat server from the left list box to right list box (if u can remember). Both the list boxes will just remain empty. And there will be no hint on whats exactly wrong. So i restored the localstore.rdf file and it started working again.

Hope this helped anyone. Dont want someone else to waste a day to solve this problem.

Converting Spreadsheet Data table to a Single Row/Column Data

March 9, 2014

Say given you have a table of data in your spreadsheet and you want to convert it in to a column of data where each row of data in the table is converted in to a column of data itself. You can do this easily using the spread sheet functions in the cells by doing the following,

  1. assume the data to be indexed 1 through n (n=total number of data cells in the data table)

    eg: data table of 5×8 will have 40 indexes

  2. for each index number associated with the data-cell determine the row and column for that data (you can easily do this with MOD and DIVIDE/INT commands, but mind the special edge case)

    eg: (with above example) index 8 corresponds to row 2, column 3

  3. Using “ADDRESS” command you can determine the cell address of a <row>,<column>

    eg: “2,3” corresponds to cell address “C2”

  4. Using “INDIRECT” command you can retrieve the value of a cell address

    eg: INDIRECT(“C2”)

A sample could be found @

Old Town Trolly Tours – San Diego

July 26, 2013

Its pretty much fun to listen to the tour guide…. Got a discounted price tour for $15 due to the XSEDE13 conference… Well worth the money…. Word of advice, sit on the right hand side of the trolly facing the front. Thats the side most of the good stuff you are gonna see…

My First MPI program

July 23, 2013

This was long overdue IMO. Here’s the simple hello world…

#include <stdio.h> 
#include <mpi.h> 
int main(int argc, char **argv) { 
 int rank, size;  MPI_Init(&argc, &argv); 
 MPI_Comm_rank(MPI_COMM_WORLD, &rank); 
 MPI_Comm_size(MPI_COMM_WORLD, &size); 
 printf("I'm the process number %d out of %d ", rank, size)); 
 return 0; 

to compile,

$ mpicc hello.c -o hello_exec

Note: if you have writtern in C++, use “mpic++” instead.

you can execute this as a normal application as usual but if you want it to execute in a cluster, use “mpirun” command.

$ mpirun -np 5 ./hello_exec

Note: “-np” is for number of processes to spawn. If you haven’t provided where to spawn the processes they will be created in the node 0 which is usually the host machine which you are triggering the MPI application. But if you know the other nodes you just need to specify those nodes. 

$ mpirun -f hosts.txt -np 5 ./hello_exec


$ mpirun -hosts host1,host2,host3 -np 5 ./hello_exec

and the mpirun will spawn processes in those hosts in round robbin fasion.

Java Swing 2D Create a Rounded Corner Polygon

July 21, 2012

Incase you are wondering I couldn’t find a straightforward method. Thus I wrote the following functions. Given a set of connecting points or a polygon the following function will return a polygon with rounded corners.

public static GeneralPath getRoundedGeneralPath(Polygon polygon) {
   List<int[]> l = new ArrayList<int[]>();
   for(int i=0; i < polygon.npoints; i++){
      l.add(new int[]{polygon.xpoints[i],polygon.ypoints[i]});
   return getRoundedGeneralPath(l);
public static GeneralPath getRoundedGeneralPath(List<int[]> l) {
   List<Point> list=new ArrayList<Point>();
   for (int[] point : l){
      list.add(new Point(point[0],point[1]));
   return getRoundedGeneralPathFromPoints(list);
public static GeneralPath getRoundedGeneralPathFromPoints(List<Point> l) {
   GeneralPath p = new GeneralPath();
   for(int pointIndex=1; pointIndex<l.size()-1;pointIndex++){
      Point p1=l.get(pointIndex-1);
      Point p2=l.get(pointIndex);
      Point p3=l.get(pointIndex+1);
      Point mPoint = calculatePoint(p1, p2);
      p.lineTo(mPoint.x, mPoint.y);
      mPoint = calculatePoint(p3, p2);
      p.curveTo(p2.x, p2.y, p2.x, p2.y, mPoint.x, mPoint.y);
   return p;
private static Point calculatePoint(Point p1, Point p2) {
   float arcSize=10;
   double d1=math.sqrt(math.pow(p1.x-p2.x, 2)+math.pow(p1.y-p2.y, 2));
   double per=arcSize/d1;
   double d_x=(p1.x-p2.x)*per;
   double d_y=(p1.y-p2.y)*per;
   int xx=(int)(p2.x+d_x);
   int yy=(int)(p2.y+d_y);
   return new Point(xx,yy);
   public static void main(String args[]) {
        JFrame f = new JFrame("Rounded Corner Demo");

        JPanel contentPane = new JPanel() {
            protected void paintComponent(Graphics grphcs) {
                Graphics2D g2d = (Graphics2D) grphcs;

                GradientPaint gp = new GradientPaint(0, 0,
                        getBackground().brighter().brighter(), 0, getHeight(),

                g2d.fillRect(0, 0, getWidth(), getHeight());
                int[][] a={{50,0},{100,50},{50,100},{0,50}};
                GeneralPath p = getRoundedGeneralPath(Arrays.asList(a));
        contentPane.add(new JLabel("test"));
        f.setSize(200, 200);

Have fun…

Bash working with the filename

March 23, 2012

In bash/sh scripting its very common that you are given a filename and have to perform various tasks on it. Following are some of the bash functions I created in order to perform them. Feel free to use them as you like.

Incase you dont know how bash functions work it is explained here. If you are only interested in how it is done just look at whats inside the function only. Thats where the magic happens.
#print the filename from the given path
 echo $(basename $1)

#print the filename without the extension
 local filename=`get_file_name $1`
 echo ${filename%.*}

#print the filename extension
 local filename=`get_file_name $1`
 echo ${filename##*.}

#print parent directory of a file
 echo $(dirname $1)

#print the absolute path of a file/directory given its relative path
 local relative_path=$1
 if [ -d "$relative_path" ]
    local absolute_path=`cd $relative_path; pwd`
 local file_name=`get_file_name $relative_path`
 local dir_name=`get_path_to_file $relative_path`
 local dir_name=`cd $dir_name; pwd`
 local absolute_path=`combine_path $dir_name $file_name`
 echo $absolute_path

#disguised to look like it just prints the number of files in a directory but infact it launches world war 3
 echo `ls -1 $1 | wc -l`

Functions in bash/sh scripts

March 23, 2012

Its pretty simple to work with functions of commandline bash/sh scripts.

Define function

This is how you define a function
  <bash command_1>     
  <bash command_n>
  echo "Hello World"

Calling the function

In order to call the function the function needs to be defined as above before you actually call it. Then you just use the name of the function
  echo "Hello World"


Passing parameters to the function

Passing parameters to the function is pretty weird. Its the same as parameters being passed to a script. The function will have its own set of $* variable where the 1st parameter is $1, the next is $2 and so on.
  echo "Hello $1 $2"

say_hello "Saminda" "Wijeratne"

Defining variables inside a function

Defining variables inside function is same as how you’d do usually in a script. Only difference is that if you want the variable to be local to the function you need to use the keyword “local” when defining it.
  local first_name=$1
  last_name=$2           #becomes a global variable
  echo "Hello $first_name $middle_name $last_name"

middle_name="Saminda"               #global variable
say_hello "Kushan" "Wijeratne"
echo $firt_name
echo $last_name
Passing a string as a variable is easy. But passing an array to a function is pretty tricky. Here’s an example on how to do it.
 eval "declare -A bio_data_array="${1#*=}
 #now bio_data_array is the array that was passed as a parameter
 echo "Hello ${bio_data_array['name']}"

declare -A bio_data
say_hello "$(declare -p bio_data)"

Returning values from the function

You’ll be surprised to know that bash functions never return anything. However you can capture what was printed by the function in the form of a string using the cool feature in bash where you can execute commands within “`” characters which the result is the output given by that command.
output_string=`say_hello $firt_name`
echo "This is what the say_hello function had to say: $output_string"
There are several other ways like using global variables or pass a variable name as a parameter to save the result of the function inside the function itself. But I prefer the above method since the function doesn’t have to worry about whether or not its a function or not.

Mounting a file as a file system in Linux

March 21, 2012

This is called mounting a loopback device.

3 steps.
  1. Creating the file that can be mounted as a file system
  2. Assigning the file as a block device
  3. Mounting the block device to a path
Creating the file that can be mounted as a file system

Use the dd command to create an empty file of the size which you want your file system.
  $ dd if=/dev/zero of=my_fs bs=1024 count=30720
of – parameter specifies the name of the file
bs – size of the block (represents x no of KB. You can specify x no of MB using xM: i.e. “bs=1M”)
count – how many blocks to be present (thus the size of the file system = bs*count)
if – from which device the file content initially should be filled with.
But still the file that gets created is not a proper filesystem yet. you need to format it using some file system type. In order to do that first lets assign the file to a loop back device (the next step)
Assigning the file as a block device

In linux a file system has to be a block device in order for it to be managed as a file system. In this particular case we use a set of defined loop back devices for our purpose. eg: /dev/loop0 up to /dev/loop8
in order to check if a particular loop back device is already being used use the command,
  $ losetup /dev/loop0
If its already being used you will see it mentioned in the output of the above command. Once you find a free loop back device to attach/assign the file to it
  $ losetup /dev/loop0 my_fs
This command needs to be issued as a sudoer user.
Now lets format the loopback device we just attached. 
$ mkfs -t ext3 -m 1 -v /dev/loop0
Effectively we are creating a filesystem inside a file using the above command. I’m formatting it as ext3 file system. You may have to use sudo again.
Mounting the block device to a path

The hard work is done. Now to just mount.
  $ mount -t ext3 /dev/loop0 /mnt/fs_mount_location/
You may ommit the “-t ext3” parameter in this case since usually linux file systems are automatically detected at mount. You may have to sudo the above command. 
Thats it actually. Once you are done you should clear up after you ofcourse. to do that just 2 commands
  $ umount /mnt/fs_mount_location/
to unmount. you may need sudo again
  $ losetup -d /dev/loop0
to detach the file from the loop back device. Need sudo again.
Steps are curtasy of

3 Lessons I never seem to learn

March 13, 2012
  1. Never trust women
  2. Never leave your work until the last minute
  3. Try to learn the 3 lessons I never seem to learn

Listening to something you already knew

March 4, 2012

I always knew that knowing something and understanding something is totally different. But I never thought that knowing something and listening to what I know can feel totally different.


Today I read a blog post of a friend of mine… Or perhaps more elaborately speaking who used to be a friend of mine… to be more exact a person who is at the other end of the path filled with alot of broken glass. I knew who she was, the kind of person who she really is before she changed (or was it I who changed?). I don’t know at which point I knew those stuff.. or how I knew for that matter. Perhaps because I’ve being in the same shoes… same fears, same doubts… but somehow that did not really connect us. I guess it made us feel that we are related. Like fruit from the same tree (but in different branches).


Ever being in front of a crowd which exceeded the hall? over 300 pairs of eyes following your every movement. When you take the Mic the slightest scratch on your head.. the smallest stutter… gets noticed like its the main highlight of the evening… At that precise moment they’ve no idea how hard it is to look at the audience without having your head feeling dizzy… stop your hands shaking of feeling cold… trying to utter words out of a mouth that all of a sudden has gone dry…. What in the world am I doing here…¬†


It was about a public speech she made last year. The very first one to a variety of people of such numbers. I was sooooo proud of her on what she is about to do… Felt like “my little girl all grown up”. Felt like all the work over the years led to this… To this one single moment of my achievement through her. My achievement in being part of making her who she is… I got the rare feeling of a feeling of being swelled with pride. It felt like a dream she had said. Back then we were still friends… there were some large cracks in the glass, but still friends…

Reading the post was one of the happiest and disappointing post I’ve ever read. I don’t know why but feels that both are the same.¬† She had done her speech splendidly… Happy because it showed how she came out of her shell to see the world. To know that she can achieve anything and everything is possible if she wants to. I could almost imagine how she was smiling when she typed those words. There’s a weird thing about achievements. It comes with a cost. “Overconfidence” one might say… “misguided” one might judge… “lost” one would proclaim… but I’d say disappointment and leave it at that (going further will not help anyone).¬† bcos less than a week later she shattered our friendship of had remained in to dust.


Friendships don’t last forever… Something which I already knew… but turns out it doesn’t matter that you did…

Answering the most hardest questions

July 28, 2011

1. How to understand women?
– Still being calculated. Says it will take more time than it took to find the answer “42”.
2. What is love?
– sacrifice (answer tested & verified)