Saturday, November 11, 2006 and hashCode make (blocking) Internet connections....

Sometimes simple calls have unexpected side effects. I wanted to update some plugins, but the update manager was hanging my UI. Looking at the stack trace reveals:

at Method)
at$1.lookupAllHostAddr(Unknown Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
- locked <0x15ce1280> (a
at Source)
at Source)
- locked <0x1a3100d0> (a

Hmm, I must say that it is very dangerous that (and URL.equals) makes an Internet connection. has the worst equals/hasCode implementation I have ever seen: equality depends on the state of the Internet. Well in the javadoc of URL.equals it says: "Since hosts comparison requires name resolution, this operation is a blocking operation.", but who reads the documentation of equals? There is a general contract around equals. Joshua Bloch writes in Effective Java: "Don't write an equals that relies on unreliable resources" (Chapter 3, page 34). Hey Sun, as far as I know, the Internet is not reliable ;-)

Do not put into collections unless you can live with the fact that comparing makes calls to the Internet. Use instead.

URL is an aggressive beast that can slow down and hang your application by making unexpected network traffic.....

I wonder if other people find this behaviour as shocking as I do....

Saturday, October 07, 2006

Tip: debug (and patch at runtime) an installed eclipse

Today I had a problem that occurred only in my installed eclipse but not in my runtime workbench.

How to start eclipse so you can attach a debugger?

You have to add the following to the vmargs: -vmargs -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009
The 9009 is used later to attach to eclipse.

How attach to eclipse?
  • create a new Debug->Remote Java Application.
  • Set the port to to 9009 (or whatever you use as the address argument in your eclipse launch)
  • On the Sources tab add the projects that you want to debug..

How to "patch" the running eclipse?

Just modify the code. Actually, I discovered this by accident. My problem was an obvious bug (missing check for null), so I fixed in during the debug session. And the usual eclipse "magic" fixed the bug in my running eclipse. It's the hot code replacement that normally happens. I (falsely) though that would only work when I start a runtime eclipse from within eclipse. But it works in any case.

Now I can fix my running eclipse while I'm normally working. The only downside is, that the two eclipse must use two different workspaces. Too bad.

Here's a flash demo video that shows how to do this step by step.

Tuesday, October 03, 2006

Help! How to manage multiple (RCP) applications in one installation?

Maybe someone reading my blog can help me. I posted essentially the message below to the equinox newsgroup and the platform newsgroup with zero response. Maybe RCP in the headline will help getting someone to read my post ;-)....

How to restrict the plugins visible to an application?

We have several applications (some of them are headless) that run from within the same eclipse installation. The problem is, that all plugins are visible from the applications. This cause problems, if extensions are used that load plugins that cannot run in the context of the headless application.

To illustrate the problem I use a simple example. A headless application that uses the org.eclipse.core.variables plugin to expand a variable. The org.eclipse.core.variables is UI free and therefore no problem. But some plugins that contribute to the variables plugin are not headless. To illustrate this, I use the ${selected_text} variable that is defined in the org.eclipse.debug.ui plugin. This causes the application to fail.

public class MyApplicationWithVariables implements IPlatformRunnable {
public Object run(Object arg) throws Exception {
IStringVariableManager vm=VariablesPlugin.getDefault().getStringVariableManager();
String message=vm.performStringSubstitution("Hello ${selected_text}!");
return EXIT_OK;

name="Minimal Headless with variables"
<run class="gr.scharf.minimal.headless.MyApplicationWithVariables"/>

Is there a way to restrict the plugins visible or loadable to an application?
Or is the only way to have a copy of the installation containing only the "good" plugins?


How the eclipse update manager could look like...

One of the features I don't like about eclipse is the update manager. A few weeks ago, I looked at different alternatives of eclipse update managers. Today Chris Aniszczyk blogged about the FireFox update manager. Interestingly, a few days ago, I created a small flash video on the FireFox update manager, because I think that shows what a user expects from a simple to use update manager.

One of the central paradigms of eclipse the idea of plugins. However from a user perspective, managing plugins is a nightmare. The eclipse update manager is way too complicated, too slow, not robust enough.

Few weeks ago I bought Eric Evans book "Domain Driven Design". I'll blog about it separately. One of the central ideas is what he calls "ubiquitous language" (e.g. read chapter one). The basic idea is to come up with a language to describe the problem domain, in our case the installation and update of plugins. The language is not only used in conversations but also represented by a formal model. The formal model is implemented in code. You can start reasoning and discuss about the model.

If I look at the eclipse update manager, the model used is a very technical model that is totally implementation centric. It is not a model a user of the update manager can simply understand. I think this is the root of the problem. We have to come up with an update manager domain model that represents the problems and tasks a user of eclipse faces and not a model that is focused on the implementation. The current implementation could be used to implement the user model, but in it self it seem not the right abstraction for users.

The FireFox update manager has an easy to understand domain model that is shown in the UI. There are extensions. An extension has an icon, a description and a set of preferences (yes the preferences of each extensions is available directly from the "Extensions" dialog. In eclipse there's no way to find out what an extension contributes to eclipse. See my blog entry "When seamless integration becomes a nightmare..."). Anyway, hit a simple button to check for updates. It's done in seconds (not minutes like eclipse). Once downloaded, you can update the plugins you want to update.

If you don't like an extension you can select an extension and "Uninstall" it. Something that is not possible with the eclipse update manager. Eclipse is a grow only system -- no way to remove features. Like windows in the old days. Once you have installed a feature there's no way to get rid of it. Only, if you regularly do backups (like I do), you can revert a previous version of eclipse by reverting a backup. But eclipse itself is grow only (*). If you have installed a few features you don't like and you cannot get rid of, you will start thinking twice if you want to install a new plugin. That's very bad for the eclipse ecosystem.

Eclipse must solve the update manager problem soon and provide a simple to use and understandable update manager that solves the problems of eclipse users.

Domain Driven Design could help come up with a update manager domain model that is relevant for eclipse users...


(*) You could also use separate extension locations for each feature you install and simply delete the location if you want to uninstall the extension. But that's a hack. The update manager (UI) does not even support dropping of extensions. I tried that for a while, but it requires a lot of discipline.

Wednesday, September 27, 2006

When a system becomes corrupt....

Have you ever had a system running stable for years and suddenly everything goes wrong?

It started last Saturday, when one of my usb-backup drives died. No big deal. I have two external backup drives with at most one attached to my system. I do weekly full backups and daily incremental backups on important data. I swap drives from time to time (I should swap them every day) and keep some old backups.

On Monday my DSL connection died. No problem, I have a ISDN USB modem I can use in those cases. The modem was cheap but the driver sucks: it uses 100% CPU even if nothing is going on. Well, no problem, I downloaded a new driver, created an XP system restore point and installed the driver. Well, I tried different versions of the driver. No one really helped, the last one crashed my system. OK, I did a "system restore", but during shutdown the driver crashed my computer. Restart, login ... baang! Windows forgot my user settings! It created a new profile. All settings lost!

No problem, I first create a backup (it's always a good idea to backup the entire system, even if is corrupt, before you mess around!) and then I wanted to back the last full backup...

Big problem! The last backup is corrupt, and the most recent backups are on my dead drive...

...for the last 12 hours I have been playing back different versions of backup trying to restore my user data. In between I have between googling for the potential problem of my setup, with little success. Whenever I restored my latest user data in C:\Documents and Settings\<username>, windows decided to create a new profile for me. I got very very frustrated and finally accepted the fact that I have to live with a new profile and I have to set up my environment from scratch. I copied all my user data into the new profile....

...Firefox, Thunderbird, cygwin, eclipse are applications that did not loose data and were running as before. But my desktop, internet explorer and many other applications that depend on the registry lost their settings. The worst case was Outlook, it wants to be reinstalled and looses all setting that are not on the exchange server...

So, I asked myself, is there a way to get my personal registry settings into my new profile? Finally I stumbled over the important files: the C:\Documents and Settings\<username>\ntuser.* files. From my "after the problem" backup I figured out that the file ntuser.dat file was missing.

Was that the key to my problem? Did loosing the ntuser.dat cause all the troubles? Ok, I had to try it. I copied an old version from a backup into my corrupt profile. Hmm, but how to tell XP to use my old profile directory again? A quick search in the registry revealed that the profile directory is stored under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList/*. I changed it, renamed my new profile to something else and restarted....

WOW! It works. My system is back. Outlook works, my desktop looks like always, all applications work as expected. I'm happy again....

What has my windows problem to do with eclipse?

Eclipse does not use the registry, but it has the magic .metadata directory. Over the last 5 years my .metadata directory got corrupt several times. If something goes wrong with the ..metadata (like running out of disk-space), it's very hard, if not impossible, to recover from that. You can, similar to windows, create a new workspace and import the projects. But then you have lost a lot of settings and you "start from scratch". My backups saved me several times here.

  • Backup the corrupted system before you do anything.
  • Make bakups. Regularly!


Wednesday, September 20, 2006

Mylar is very cool, however sometimes it drives me nuts...

Mylar is an eclipse technology project. It makes it easy to focus on a task you are working on, by hiding the information that's not relevant to the current task.

How does it know, which information is relevant? It "looks over your shoulder" and remembers the files, classes and methods you have looked at. With some magic it puts some weight on the places you have been. For example if you get back to some place or even edit there, it gets more weight than just looking once at the file. But you can also tell mylar explicitly that you are interested or not interested in some context.

How does it hide irrelevant information? Well, in the package explorer, outline etc you see only the classes and methods in your context. There's even a mode that shows the relevance by the background color. And really important places are shown in bold. To build up context, you can disable mylar on the view to see everything. I never use the editor folding features of mylar, because I don't like folding.

If you want to learn more, I highly recommend the getting started flash demon.

There are also integrations with bug tracking systems, and it seems that this is how most people are using Mylar. Unfortunately, we use a commercial bug-tracking system that is not supported by mylar. But I find mylar very useful, even without the bug tracking system integration.

However, sometimes I hate mylar: I am working on a problem, and I find something interesting I want to look at later. So, I create a new mylar task. That's all fine. But now, when I want to add context to this task, I have to start from scratch, because mylar closes all my editors and collapses all my trees. However, if I have switched off mylar (that is: I have no active mylar task), and then create a new task and activate that new task, everything is good. In this case mylar does not close all my editors, but is clever it letting me build up my context from where I am. (I created a little flash demo to illustrate this workflow). I talked about this on the newsgroup, and it seems that my workflow is very special. I wonder if I am the only one having this workflow problem with mylar, therefore I created a bugzilla entry: bug 157933....

Saturday, September 16, 2006

Don't swallow InterruptedException. Call Thread.currentThread().interrupt() instead.

Have you ever written the following code?
try {
} catch(InterruptedException swallowed) {
// just logging is also not a useful option here....

I have! I newer knew what the heck to do with those annoying InterruptedException when I simply wanted to call Thread.sleep(..). What is this InterruptedException? Why is it thrown? Why can't I ignore it?

Before I explain the whys, here is what you should do (if you don't re-throw):
try {
} catch(InterruptedException e) {
// Restore the interrupted status

What is the InterruptedException?

There is no way to simply stop a running thread in java (don't even consider using the deprecated method stop()). Stopping threads is cooperative in java. Calling Thread.interrupt() is a way to tell the thread to stop what it is doing. If the thread is in a blocking call, the blocking call will throw an InterruptedException, otherwise the interrupted flag of the tread will be set. A Thread or a Runnable that is interruptable should check from time to time Thread.currentThread().isInterrupted(). If it returns true, cleanup and return.

Why is it InterruptedException thrown?

The problem is that blocking calls like sleep() and wait(), can take very long till the check can be done. Therefore they throw an InterruptedException. However the isInterrupted is cleared when the InterruptedException is thrown! (I have some vague idea why this is the case, but for whatever reason this is done, that is how it is!)

Why can't InterruptedException be simply ignored?

It should be clear by now: because ignoring an InterruptedException means resetting the interrupted status of the thread. For example, worker threads take runnable from a queue and execute they may check the interrupted status periodically. If you swallow it the thread would not know that it was interrupted and would happily continue to run.

Some more thoughts
Unfortunately it is not specified that Thread.interrupt() can only be used for cancellation. It can be used for anything that requires to set a flag on a thread. So, ending your task or runnable early might be the wrong choice, if the interrupted status is used for something else. But common practice is to use it for cancellation. But even if it is used for something else, you code does not have the right to reset the interrupt flag (unless you are the owner of the thread).

To learn more read the nice article Dealing with InterruptedException by Brian Goetz.

Or read Java Concurrency in Practice By BriaBrian Goetz, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, and Doug Lea. It's a great book! If you program in java 5 this book is a must read!. I bought the book after I read Brians artikle. I have not yet read the entire book, but what I have read impresses me. It gives a lot of theorie and options. Very competent and complete, but I'm missing a set of simple patterns for concurrent programming. I'm looking forward to Doug Leas 3rd edition of Concurrent Programming in Java

Summary: If you don't know what to do with an InterruptedException call Thread.currentThread().interrupt()

Sunday, September 10, 2006

Pitfalls of Long.parseLong/Long.decode...

What is wrong with this code?
assert 0x0cc175b9c0f1b6a8L == Long.parseLong("0cc175b9c0f1b6a8",16);
assert 0xd41d8cd98f00b204L == Long.parseLong("d41d8cd98f00b204",16);
The second Long.parseLong will fail in the second line:
java.lang.NumberFormatException: For input string: "d41d8cd98f00b204"
The reason is that javas long is signed, but 0xd41d8cd98f00b204L is an unsigned long. Interesting, but annoying, if you want to parse an unsigned long in java. It makes Parsing and verifying hex, octal and decimal numbers more complicated, if you have a field that represents a C/C++ unsigned long (a 64 bit number)....

The solution is to use BigInteger:
assert 0x0cc175b9c0f1b6a8L == new BigInteger("0cc175b9c0f1b6a8",16).longValue();
assert 0xd41d8cd98f00b204L == new BigInteger("d41d8cd98f00b204",16).longValue();
However, you must ensure that the BigInteger does not exceed 64 bits. So here's my unsigned long parser
public static long parseUnsignedLong(String s, int radix) 
throws NumberFormatException {
BigInteger b= new BigInteger(s,radix);
throw new NumberFormatException(s+" is to big!");
return b.longValue();
Note: if you want to do any kind arithmetic with unsigned longs (like min/max checking) you have to use BigInteger objects.... Unless you are only interested in the bits of the long, the return value of my parseUnsignedLong is not really useful: it should better return the BigInteger!

Thursday, September 07, 2006

The Dependency Injection Pattern: an alternative to Factories and Service Locators

On my vacation I listened to about 30 pod-casts. Although most of what I heard was not new, it still was a good refresher and exciting to listen to. It also inspired me to order a few books and make me think more about what I am doing as software engineer.

One pattern that was new to me is Dependency Injection. It was mentioned in software engineering radio Episode 2 on Dependencies. Instead of using a Factory or a Service Locator (like OSGi), make your class have some members referring to the interfaces it uses. The Dependency Injector then uses either the constructor or some set methods to provide your class with the implementations of the classes your object needs. Read the One minute description and the Two Minute Tutorial of PicoContainer (a nice little Dependency Injection Framework) to see what I mean.

Martin Fowler wrote a long article about Inversion of Control Containers and the Dependency Injection pattern.

I was always wondering why using interfaces when you have only one implementation of the interface anyway. So, why bother? With Dependency Injection you can test your object easyly using Mock Objects. Jeremy Weiskotten wrote an Dr.Dobb's Article on why Dependency Injection is very helpful to create testable and decoupled objects.

Dependency Injection makes it very clear which interfaces your objects depend on. This makes refactoring, testing and understanding code easier. Factories and Service Locators often provide more products than needed by a single class and therefore you cannot really tell what the class depends on.

I'll play with Dependency Injection :-)

Monday, August 21, 2006

Going on vacation with a mp3 player full of geek pod-casts...

I'm going on vacation for two weeks to Athens and Crete. My wife is Greek and therefore we go every summer to Greece. Going on vacation also means no laptop (that's not my deceison ;-). So usually, I take some geek books with me. This time I loaded my mp3 player with the 9 Callisto pod-casts from Eclipse Zone and a few of the Software Engineering Radio pod-casts.
I tried it on Friday. It's a almost like being in a conference call. But it's better: I can wind back if I get sidetracked and I don't have to be afraid that suddenly someone says: "And Michael, what do you think?....". I was shopping and listening to Richard Gromback on GMF. I was waiting in the queue to pay and when it was my turn, I started talking in English to the German cashier -- lost in cyberspace...

One thing I think pod-casts should do: Please say at the beginning of the pod-cast when it was recorded! If someone says: "Next month we'll release foobar..." it is annoying not to know when next month is or was...

And now, relaaaaaxxx, summer, sun, beach, fun -- for 2 weeks -- I'll be back Sep.5 late afternoon....

Friday, August 18, 2006

Blog comments, my mistakes and good feedback...

Marko Schulz asked me why his comments did not appear in my blog. I checked it and I realized that I had a setup problem with my blog (my mistake). Now all comments are visible and new comments will be shown automatically! I'll check them for spam later.

Here's what I learned from the comments:
I checked all comments and I found a few spams, but most comments brought up valid points. Thank you for your feedback!

Thursday, August 17, 2006

MDSD/MDA framework openArchitectureWare 4.1 is available at

I just read the announcement that openArchitectureWare 4.1 is available. openArchitectureWare is hosted at It is one of the coolest projects at but it seems not to get much attention. If you are interested in MDSD or MDA take a look at openArchitectureWare - openArchitectureWare is really cool!

Parsing and verifying hex, octal and decimal numbers...

How to parse a number that might be octal, decimal or hexadecimal. Numbers like 0xFF, 0x1e, 077, -123, -0x12, -066. This must have been solved a million times, and here's my version:

Thank you for all the comments! My code is stupid! Use Long.decode(numberString).longValue() Instead!
String sign="";
int base=10;
if(numberString.startsWith("-")) {
if(numberString.startsWith("0x")) {
} else if(numberString.startsWith("0") && numberString.length()>1) {
return Long.parseLong(sign+numberString,base);

OK, and here is my VerifyListener:
class NumberVerifyer implements VerifyListener {
final boolean fSigned;
NumberVerifyer(boolean signed) {
public void verifyText(VerifyEvent e) {
Text text = ((Text)e.widget);
StringBuffer fulltext = new StringBuffer(text.getText());
fulltext.replace(e.start, e.end, e.text);
String sign=""; //$NON-NLS-1$
sign="-?"; //$NON-NLS-1$
e.doit = fulltext.toString().matches(sign+"(0?|[1-9][0-9]*|0x[0-9a-fA-F]*|0[0-7]+)"); //$NON-NLS-1$

Wednesday, August 16, 2006

Vote for the eclipse 3.3 release train name. Europa is a bad choice!

Vote for the Eclipse Release Train Name (2007). There has been some discussions in bugzilla.

I think Europa is a very bad choice for two reasons:

1. There are too many Google hits already if you search for eclipse europa.

2. In many languages Europa means Europe and this will confuse. Messages like the "Europa Build Workshop", sounds for many non-native speakers like "The Build Workshop Europe". If English is your native language, you might not understand this point, but for Germans this is very confusing. For the same reason you would not call a workshop held in the nice Austrian village called Fucking the "Fucking Workshop" ;-)....

Tuesday, August 15, 2006

Am I the only person having problems with the update manager?

I wonder if I am the only person in the world using the update manager and having problems. Two weeks ago I reported a real show-stopper update manager bug: Update does not work if *ANY* error is found in configuration. I expected that it would be marked as a duplicate but I seem to be the only person having the problem. I cannot finish the updates dialog because of some mysterious errors:

The annoying thing is that "Manage Configuration" seems happy and shows no error:

The error is caused by some installed features that require a specific version of a plugin.

<?xml version="1.0" encoding="UTF-8"?>
<feature id="broken.feature" label="Broken Feature" version="1.0.0">
<import feature="org.eclipse.platform" version="3.1.2" match="perfect"/>

What puzzles me the most is not the bug itself, but the fact I seem to be the only one getting the bug (I get it with 3.2 and 3.3M1).....

If you want to try it, just unzip this feature in your eclipse/feature directory and restart eclipse and try to install a feature using the update manager.

Fix the feature.xml file by removing the required version string.
Or use another working eclipse installation and install the plugins into a new extension location and add the extension location to your eclipse using "Manage Configuration".

Update manager battle: the players Yoxos - YUM - eclipse...


I am very frustrated with the eclipse update manager. In my opinion, it is simply unusable. But what are the alternatives? A few weeks ago, I bought a 1 year subscription of yoxos for $99. Unfortunately, since then, no new updates appeared on my yoxos update manager. The yoxos update manager is quite cool. It's a perspective that allows you to select the plugins you want:

This looks very much like the yoxos on demand site (yes, this is a screenshot of an ajax application!):

I don't know how it works, when new updates are available, but I expect it will work smoothly (well, I payed for it -- therefore it has to work ;-))

TUM - Tikal Update Manager

TUM (Tikal Update Manager) is a open source project forge project called tikal run by Tikal.

They create a dialog with some cool icons. Yoxos seems much more mature, but TUM was just announced....

The Eclipse Update Manager

The eclipse update manager seems also to be enhanced. I have not seen it (because I hope for yoxos to install it for me...), but the screenshots seem promising.

The battle shall start...

I really hope that finally the update manager gets more attention. My favorite is clearly yoxos, because they don't use annoying blocking dialogs, but a perspective. The funny thing is, that eclipse 1 used a perspective as well, and in eclipse 2 it became wizard based...

Monday, August 07, 2006

How far are the hotels from the eclipse summintOctober 11-12 2006 in Esslingen/Stuttgart Germany?

I'm about to register for the The eclipse summit 2006 October 11-12 in Germany. On the web page there are 4 hotels suggested, but no clue how far they are away from the actual summit (are they in walking distance?). The summit seems to be at Ebershaldenstraße 12, 73728 Esslingen, Germany. I called all of them to ask for the price for the eclipse summit. The hotels all seem to be in the 100 Euro category. I think breakfast is included in all cases.

Best Western Premier Hotel Park Consul Esslingen
Grabbrunnenstr. 19
73728 Stuttgart/Esslingen am Neckar
Tel: +49(0)711-41111-0
Fax: +49(0)711-41111-699
Distance: 150 meters
Single Room: 110 Euro

Hotel Linde Berkheim
Ruiterstraße 2
73734 Esslingen am Neckar
Tel: +49(0)711-345305
Fax: +49(0)711-3454125
Distance: 4 km
Single room: 85 Euro - Double room 114 Euro (until Sep. 8th)

Hotel Am Schillerpark
Neckarstr. 60, 73728 Esslingen am Neckar
Tel: +49(0)711 931 33-0
Fax: +49(0)711 931 33 100
Distance: 1.2 km (walking distance 800 meter)
Singe Room: 89 euro (20 rooms for the summit)

Ringhotel Rosenau
Plochinger Straße 65
D-73730 Esslingen am Neckar
Tel: +49(0)711 315 45 60
Fax: +49(0)711 316 13 44
Distance: 1 km
Prices: The lady at the reception did not know about the "Eclipse Summit". I should call tomorrow before 4PM.

How to quickly add a new repository location to CVS...

The eclipse Add a new CVS Repository dialog allows you to quickly fill the form, if you drop a string like into the Host: field. If you see a string like
cvs login 
at sourceforge, grab the highlighted part (including the colon before pserver)...

You can also select a location in the CVS Repositories view and "Copy to Clipboard" and send it to someone. The receiver can then drop it into the Add a new CVS Repository.

Saturday, August 05, 2006

Eclipse was hanging my machine regularly -- solution -XX:MaxPermSize=128m

I have quite some plugins installed in my eclipse installation. Since a few weeks, eclipse was running mad from time to time, my XP laptop was totally starving, I was not even able to get to the task manager to kill eclipse (keyboard and mouse barley reacted). The only solution was to kill my machine :-(.

Well, but how to find out who is the bad guy? Which of the many plugins I have installed "killing me"? I was using Stack Trace, a cool application that lets you attach to eclipse and get a stack trace.

Most of the time the stack traces of the wild application ended in:
 at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(
at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl

Hmm, the class loader puts the class files in a special area of the garbage collector, (perm generation). The starving (100 % CPU and being really bad) seemed to be caused by not enough memory in the perm space. To fix this, I added -vmargs -XX:MaxPermSize=128m to the shortcut that starts eclipse. That solved the problem! The sun default seems to be 64MB (I could not find information for java1.5).

But how much is the perm size really? How to find this out? Today, I found a blog entry by Igor Shabalov describing a cool tool called jconsole, that comes with jdk1.5.0, that allows you to inspect memory related information of your java applications life. All you have to do, it to add to the eclipse -vmargs. Then you can attach to eclipse and see life the different garbage collection pools and the loaded classes and threads -- pretty cool...

Friday, August 04, 2006

How to create apply a patch that contains changes in multiple projects?

Eclipse has a nice feature to apply patches (context menu of a project: Team->Apply Patch....). If you have multiple projects under CVS control, then you can create a patch that contains changes from multiple projects. The patch looks slightly odd, because id adds some additional lines that tell eclipse which projects a file belongs to. This has is new in eclipse 3.2 (bug 110481).

However if you have a patch created with diff outside eclipse that contains files from multiple projects, eclipse cannot apply the patch.

To apply my multi project patches I wrote a small Eclipse Monkey script that converts a patch on the clipboard to a Eclipse Workspace Patch 1.0, by adding some additional lines.

To install and run the script:

  • Install Eclipse Monkey (if you have not already installed it)
  • Copy the script below (including the odd lines at the beginning and the end) to the clipboard
  • In the Monkey menu do Paste New Script
  • Now you can convert patches to Eclipse Workspace Patch 1.0, by copying that patch to the clipboard and running Monkey->Tools->Convert patch in clipboard to workspace patch

--- Came wiffling through the eclipsey wood ---
* Menu: Tools > Convert patch in clipboard to workspace patch
* Kudos: Michael Scharf(eclipsemonkey @ scharf . gr)
* License: EPL 1.0

// pseudo imports


function main() {
var patch = getFromClipboard();
if(patch == null) {
showMessage("The clipboard does not contain a string!");
} else {
// is this already a workspace patch?
// the (?m) makes sure that the ^ matches the beginning of a line
// and not just the beginning of the string!
var pattern=Pattern.compile("(?m)^### Eclipse Workspace Patch 1.0");
if(pattern.matcher(patch).find()) {
showMessage("This is already a Workspace Patch!\n" +
"It contains a line beginning with:\n" +
"\"### Eclipse Workspace Patch 1.0\"");
} else {
var messages = new StringBuffer();
patch = convertToWoskspacePatch(patch, messages);
// has it been converted?
if(patch == null) {
showMessage("The clipboard does not contain a valid patch.");
} else {
// OK let's put it on the clipboard
showMessage("Patch converted to clipboard\n\n" + messages.toString());

// show a simple message dialog
function showMessage(message) {
window.getShell(), "Convert patch to workspace patch", message);

function convertToWoskspacePatch(patch, messages) {
var reader = new BufferedReader( new StringReader(patch));
var patchBeginPattern = Pattern.compile("^(---|[+][+][+]|RCS file:)\\s+([^\t\n,]+)");
var result = new StringBuffer();
result.append("### Eclipse Workspace Patch 1.0\n");
var projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
var guessedProjects = new ArrayList();
var patchFound = false;
var line;
var prevLine = null;
var hunkFound = false;
while((line = reader.readLine()) != null) {
var m = patchBeginPattern.matcher(line);
if(m.find()) {
patchFound = true;
var fileName =;
var pathSegments = fileName.split("[/\\\\]");
var segment = 0; // the segment in the path that is the project
var projectName = null;
for(var i = 0; i < pathSegments.length; i++) {
var name = pathSegments[i];
if(isProjectName(projects, name)) {
projectName = name;
segment = i;
// report every guessed project only once
if(!guessedProjects.contains(projectName)) {
messages.append("Guessed Project: ");
if(projectName != null) {
result.append("#P ");
result.append("Index: ");
// concat the remaining path segments
for(var j = segment + 1; j < pathSegments.length; j++) {
if(j != segment + 1) result.append("/");
if(line.startsWith("+++")) {
if(!hunkFound) {
messages.append("No project found for: ");
hunkFound = false;
if(prevLine != null) {
prevLine = line;
if(prevLine != null) {
return null;
return result.toString();

function isProjectName(projects, name) {
// is the name a name of a project?
for(var i = 0; i < projects.length; i++) {
return true;
// ok let's guess...
if(name.startsWith("com.") || name.startsWith("org.")) {
return true;
return false;
function putOnClipboard(str) {
var clipboard = new dnd.Clipboard(window.getShell().getDisplay());
try {
clipboard.setContents([str], [dnd.TextTransfer.getInstance()]);
} finally {
function getFromClipboard() {
var textTransfer = dnd.TextTransfer.getInstance();
var clipboard = new dnd.Clipboard(window.getShell().getDisplay());
try {
return clipboard.getContents(textTransfer);
} finally {

--- And burbled as it ran! ---

Friday, July 28, 2006

Why is super.super illegal?

Well, from time to time I have the need to call super.super. I wonder why this is illegal. Doing some research on the Internet, the best answer I can come up with is, that it breaks encapsulation of the super.super class. Hmm, probably true in a clean world, but sometimes you really want to call back back the original functionality:

class A {
protected void foo(){..}
class B extends A {
protected void foo(){;
class C extends B {
protected void foo(){; // it is illegal to omit the stupid stuff of class B

Yes, B should not do stupid things. But why can't C undo what B does? In real software systems, that's exactly something that is somtimes needed. The answer that B should provide access to if B thinks C would need it does not really satisfy me...

Come on, if java would really be concerned about encapsulation, all methods would default to final unless otherwise specified. Does everybody think about the fact that any non-final public or protected method can be overridden? No! We live with this accidental breakage of encapsulation and why is the small breakage of encapsulation that super.super does forbidden? Hey, a subclass can just override any non-final method without calling super at all, right? And C can call any method on B or A, but not

But maybe someone can give me an explanation that can convince me....

I hate ClassCastExceptions...

...because they don't tell me what the class of the "wrong" object was. No message, just empty. Where is the difficulty in telling me, what the actual type of the object was that caused the class cast exception? I rarely see them, but when I see them it's not informative enough -- I have to run the debugger but those rare class cast exceptions are often hard to reproduce...

Sun, please add runtime type of the casted object to the ClassCastExceptions message

How to setup some plugins to use java 1.5 in a java 1.4 workspace?

Most of the eclipse projects use and require java 1.4. Sometimes you want to create a new project to use java 1.5. If you simply install and select a java 1.5 in the Preferences->Java->Installed JREs, that would work, but cause potential problems. One problem is that you might accidentally use 1.5 features in 1.4 projects. A simple statement like:
string.replace("foo", "bar")
complies in this setup but will not run with a 1.4 jre, because
replace(CharSequence target, CharSequence replacement)
is new in 1.5.

The solution is to setup only the plugins that really need 1.5 to use 1.5 Eclipse has the concept of Execution Environments to specify which java JREs a plugin is compatible with.

1. set in the preferences an 1.4 jre as default and have an 1.5 installed:

2. In the project properties set the java compiler 1.5 (which is Compiler complience level 5.0 -- how I love the ever changing java version naming...):

3. Set the execution environment in the build path to J2SE-1.5:

4. In the plugin MANIFEST.MF, set the execution environment to J2SE-1.5 as well:

You could also directly add the following line to the MANIFEST.MF file

That's it :-)

Friday, May 05, 2006

How to start the OSGI console?

Yesterday, I posted two bugs for 3.2. For both bugs I got the reply I should use the osgi console to get some information. In one case to get the loaded plugins and in the other case to get a stracktrace of all threads. So, how to start the osgi console?

I found the Gathering Information About Your Plug-in page.

On windows you have to start eclipse with java.exe (instead of javaw.exe) in odrer to ge a console window. Therefore, add -vm C:\YOURVMPATH\bin\java.exe tho the eclipse start command (or shortcut). To get the OSGI console -consol as startup parameter.

Now to see all plugins (and the state of the plugins) simply type ss into the console. To get a stracktrace of all threads hit ctrl-break in the console window (I had a hard time finding the break key on my keyboard. it's the top right key on my keyboard)

Thursday, February 23, 2006

What does eclipse API freeze mean?

The eclipse 3.2 APIs have been frozen. John Arthorne has send a mail to

Between now and the 3.2 release, all changes to API require the following action before releasing any code:

  1. A bug report describing the change, and the reason it is required.
  2. Approval from a PMC member (in the form of a +1 on the bug report).

Also, if it is a breaking API change, you should search for references across the SDK, and coordinate the release with any clients that have already adopted the API being broken.

The PMC has asked Boris Bokowski and I to track API changes during this period. Please also CC either Boris or myself on the bug so we can keep track of the changes.

Monday, January 30, 2006

SWT/JFace integer flags and constructors

SWT/JFace is pretty cool. But one thing I will never understand is why the heck are the flags in the constructor of widgets integers. Let's take TableViewer as example: TableViewer(Composite parent, int style). When you want to set style parameter, code completion does not help. So you have to read the (3.1) javadoc of TableViewer it says: @param style SWT style bits. Great, but not very helpful. Ok if you are clever, you know that TableViewer passes the status flags directly to the Table constructor. The documentatios there there indicates that the following flags can be used SWT.SINGLE, SWT.MULTI, SWT.CHECK, SWT.FULL_SELECTION, SWT.HIDE_SELECTION, SWT.VIRTUAL
Ok this gives you a hint, what to use. But if you follow the link to SWT.MULTI, you read: "Used by Text,List and FileDialog"... Hmm, no mentioning of Table....

I don't want to blame the documentation. The problem comes from the design choice to use integer bits constants in the first place. If you look into the class SWT, you are simply overwhelmed by all the integer constants. I see two solutions (in Java 1.4): >
  1. eclipse supports structured comments for code completion, and the javadoc would reflect the flags correctly.
  2. Use some classes representing the flags:
If Table would have a public static inner class like this:

public static class Style {
int flags;
public Style(){}
protected Style(int flags) {
public Style multi() {
return new Style(flags|SWT.MULTI);
public Style full_selection() {
return new Style(flags|SWT.FULL_SELECTION);
Then the constructor of TableViewer and Table would take this class. You would have all the benefits of code completion and documentation. Internally, SWT could still use integer bit flags, but as a user I would have a fully typed constructor: Instead of new TableViewer(parent,SWT.MULTI|SWT.FULL_SELECTION) I would use the fully typed construct new TableViewer(parent,new Table.Style().multi().full_selection()). Code completion would help me. No more wrong flags! I would love to see additional constructors(and methods) with typed versions....

Thursday, January 26, 2006

Two projects approved: Mobile Tools for Java (MTJ) and Native Application Builder (eWideStudio)

Yesterday I attended the the creation review of two projects, both are part of the DSDP (Device Software Development Platform) top level project:
  • Mobile Tools for Java (MTJ): The project provides tools for java development on mobile devices. A kind of PDE for mobile devices. It does not provide any library on the devices, but tools for developers to create software on those devices. It deals with deployment to a development target (emulator or real target), device emulators, the build process and debugging. Nokia, from Finland, is the driving force.
  • Native Application Builder (eWideStudio): There is a cool Japanese open source UI library called WideStudio/MWT. It runs on all kind of operating systems but is also tuned for mobile devices. If you have ever been in Japan, you might know that Japan are far ahead when it comes to mobile devices compared to US and Europe. This project will integrate this library into eclipse and CDT. There's also a UI builder for eclipse (I should have asked if it is integrated into VE or if it is independent). There is some overlap with eRCP and eSWT, but this is a C/C++ library. Since it's Japanese (sponsored by Fujitsu), you don't have to worry about problems with 16 bit characters ;-).

Wednesday, January 25, 2006

A List of all Component Areas of Platform UI

Platform UI is divided into more than 50 areas, like JFace, KeyBindings, ProgressBar, Viewers, Wizards, IDE etc. In bugzilla, bugs are tagged with square brackets in the bug report subject headings to indicate the affected area.

TheComponent Areas for Platform UI lists the name, a short description, a link to the related bugs and the owner of the component area.

It's also a cool starting point to understand what is in the eclipse platform....

Tuesday, January 24, 2006

Eclipsecon recommendations...

Eclipse-con allows you to write your personal recommendations which talks you think are interesting and what you want to attend. Just look at this, at the bottom you can choose which recommendations you want to highlight. It's a cool idea. So, I did it. I created an new eclipsezilla entry of type "Recommendation". Then I read the program and I wrote down my thoughts while deciding which talks I want to attend. Just use the eclisezilla id of the talk (the and put cite it as 'submission #123' in the text. My recommendation got be accepted :-)

Saturday, January 21, 2006

How to speed up eclipse on a Laptop: disable virus-scanner, partition disk, upgrade memory

I have a Dell Lattitude 600 with 1GB of memory. Starting eclipse and building workspaces is slow. So I was looking for ways to improve speed. Here is what I did over time:

  • Disabled the virus scanner for the eclipse directory and the workspace. McAfee's on-access-scan scans the entire file when a process accesses it. When eclipse starts is only reads small fractions of .jar files. However McAffee scanned the entire file which really slows down start-up by a factor of 2: cold start-up (=newly booted machine) 95 sec without versus 215 secs with virus scanner on.
  • Partitioned my disk: I tried all kinds of defragmentation (oodefrag and diskkeeper), but nothing really helped, some made it even worse.. However one problem is that compiling creates new files and that leads to new fragmentation. Now I created a relatively small partition with my workspace. Even if this gets totally fragmented, the disk head in confined within the partition. It gave me some speedup, but I have not measured it, but it was dramatic. I wish there was a defragmentation tool, that could observe the startup of eclipse and then rearrange the files so that the access is optimal. I know such tools exist for the startup .exe files, but we need something for the startup of a system like eclipse....
  • Upgraded the memory to 2Gb and disabled the page file: Yesterday, I did the upgraded and it's great. With 2 eclipse open, outlook, trillian, thunderbird, firefox, and a few other programs, I use about 1.5Gb of memory with enough space for the disk cache. That's a real blast: because no application gets paged out anymore, I don't have to worry about switching between applications. No more long interruptions when eclipse garbage collects. It's so new, I still can't believe that I don't have to wait anymore when I switch between applications. And 2 workspaces open in parallel is no problem anymore....

In a nutshell: It's all about minimizing disk access.

Tuesday, January 17, 2006

MDSD: A European Phenomenon?

Yesterday, I wrote about my confusion with the 4 metamodel layers of MOF. Ed Willink )GB!) pointed me to a nice (French) paper about MOF. Their application of the layer is very similar to my understanding :-).

When searching for concepts around MOF and MDSD there very many European hits:

Is this a European Phenomenon? There is a kind of pattern: many new concepts are invented and researched in Europe, but commercial success often comes when American companies pick it up....

I am confused by OMG MOF 4 layers applied to MDSD and UML...

Today I tried to explain to some colleges the 4 layers of the OMG Meta-Object Facility (MOF). At first it sounds quite trivial:

  • Level M0: User Object Layer (Instances)
  • Level M1: Model (DSL – Domain Specific Language)
  • Level M2: Meta-Model (Schema description Language)
  • Level M3: Meta-Meta-Model (The Schema of the Schema)

Surprisingly applying the levels to concrete problems is not always obvious or straight forward.
I used the plugin.xml file as an example. I take here a MDSD centric approach, by assuming that the plugin.xml file "generates" the plugin....
  • Level M0: (Instance) The deployable component
  • Level M1: (Model) The plugin.xml file itself
  • Level M2: (Meta-Model) The extension point schema description (.exsd) files
  • Level M3: (Meta-Meta-Model) Schema of the .exsd files (implemented somehow in the .exsd editor)

Someone (a compiler person) asked me, how I would apply this to a programming language like C.
  • Level M0: (Instance) Executable code
  • Level M1: (Model) .C file (or a AST (Abstract Syntax Tree) representation)
  • Level M2: (Meta-Model) C language syntax definition (e.g. in yacc)
  • Level M3: (Meta-Meta-Model) Yacc language syntax definition

In this case, the meta model describes the constraints on the are AST (that's what the CDT does). This shows, that it makes sense to have a DSL (Domain Specific Language) at some levels. The DSL of C is simply the c syntax. The DSL of the c-syntax is yacc (or EBNF)... It is also interesting to have transformation between different representations of a model at the same level. C versus AST, yacc versus EBNF... The "code generation" happens between M1 and M0 (compiling). Another code generation happens between M2 and M1 when using a compiler-compiler like yacc.

But whenever I read about UML and MOF I get confused. This might have to do with the fact that I never really used UML....
  • Level M0: (Instance) Generated C/Ada code
  • Level M1: (Model) Concrete UML diagrams
  • Level M2: (Meta-Model) UML "language"
  • Level M3: (Meta-Meta-Model) ??

Again, a generator/transformer is applied between M1 and M0. Is this a correct application of MOF to UML?

But explaining both (the MDSD and the UML approach) to someone who has not been exposed to modeling gets very confusing.

So, in "my world" I prefer to see the MOF hierarchy very MDSD centric. I wonder if the MDSD centric view is confusing for UML experts is is the a natural way to see the world....

Saturday, January 14, 2006

The new jface.databinding needs users....

Yesterday I met Boris Bokowski. He is member of the core UI team in Ottawa and he worked on the jface.databindings framework. The databinding frameworks simplifies linking between UI elements and data models. You essentially link an attribute of a model with a widget, like a text field, checkbox or a tree ore table viewer. The framework registers listeners to the model and the widget and when one changes the other gets updated. It has also support for validation.

It is not clear if it will be API or experimental in 3.2. Feature freeze is soon, and users of the framework are needed.

One interesting idea in jface.databinding is that UI elements and data models are treated the same. That means, the same mechanism (IUpdatable) is used to talk to the UI and to the data model. IUpdatableFactory creates an IUpdatable for an Object. Default IUpdatableFactory for SWT widgets and java classes (using bean properties) exist. This makes jface.databinding very flexible. But this flexibility makes it too complicated for my taste. I think it suffers a bit from trying to solve too many problems. If it would be limited to provide binding needed for typical dialogs (standard SWT elements), it would cover the 80% case. Getting 100% and being very simple is probably not possible.

I have created several similar databinding frameworks in my career. The first ones were based on ET++. Later I create a binding framework for swing and recently one for SWT. The major difference between my binding frameworks and the jface.databinding is that there are widgets on one side and a datamodel on the other (no attempt to unify data access and UI access). A "ValueAccessor" represents an attribute in a model. ValueAccessor provides information typically needed for dialogs: value, valueAsString, isEnabled, isDefault, default, labelProvider (jface.databinding.IUpdatable in contrast, does not model enablement nor defaults nor label providers). My bindings is much less generic but it is much more targeted to bind a model to a UI. You then essentially bind a widget with a valueaccessor. My Binding class knows how to bind SWT widgets to ValueAccessors.

There is already a kind of very simple databinding in eclipse: The preferences.FieldEditor classes. This is limited to binding to preferences and it also provides some automated layout. And it is not flexible enough to be a general binding fremawork. But I wish the jface.databinding would have some simplicity of the FieldEditors...

Maybe a simple layer on top of jface.databinding could help....

Anyway, I wonder what others think about the jface.databinding framework...


Thursday, January 12, 2006

Stop Windows Update to Reboot Nag Dialog: sc stop wuauserv

When installing updates on Windows XP SP2, sometimes there is this annoying dialog that forces you to reboot your system. If you say "No" it will come up after a few minutes again and again....

To stop this, run the command sc stop wuauserv. This will stop the update service. After the service is stopped, the nag message stops, too. Then you can reboot when you have time. The service will restart when you reboot.

When seamless integration becomes a nightmare...

Eclipse is a great integration platform. There are many plugins that work together very nicely. As a user you don't have to worry where a menu item, a new wizard, a preference page, a view or an editor, etc comes from. You install a plugin (or add-in or extension) , and it's integrated. Great!

However, the dark side is, that it's very hard to figure out what a particular "plugin" is contributing to eclipse. Just make the experiment: install 30 plugins you have never used before from into your eclipse installation. Now you have new views, editors, context menu entries, toolbar items, menu items, new wizard items, export/import wizard entries, preference pages, perspectives, help pages, cheat sheets, property pages, keyboard shortcuts, perspectives... But you have no idea which contribution belongs to which plugin. But without a map in your mind what a particular plugin is contributing it is very hard to use and it's hard to understand what to expect from a new plugin.

My personal strategy is to install plugins one by one into a well known eclipse environment. I take some time trying to figure out what the contributions of a plugin are. That's tough enough for me as an experienced eclipse user. It must be a nightmare for someone who starts using eclipse, because he typically starts with a "product" that consists of a set of pre-installed plugins (just like installing 30 plugins at once)... I also install each "plugin" in its own eclipse extension location so I can easily uninstall it later (but that's another story). Really problematic are contributions to wizard pages and context menus of some objects in tree views. Unless you have selected the right obeject you don't see the contribution. I often install a plugin and then I ask myself: "And now? How do I find out where it contributes?". This is particularly problematic with small not well documented plugins: I install it and I have no clue where search for its contributions.

What could be done to help users identifying the things that have been added by a plugin? Maybe a kind of plugin inspector (feature inspector), that lists in a view all the contributions of a plugin (feature, add-in, extenison).

Windows highlights newly installed programs in the start menus. Maybe there could be a setting to highlight the contributions of a particular feature.

Any ideas how to solve the problem?

"Plugin": an overloaded and confusing term in eclipse

When people talk about "plugins" in the context of eclipse, they mean two very different things:

  1. Technically speaking a "plugin" is an installable OSGi plugin, which ends up in the plugins direcory of an eclipse installation (or one of its extension location) and gets loaded when eclipse starts. It can either be a directory or a .jar file. It must contain a MANIFEST.MF and/or a plugin.xml file. Multiple plugins can be assembled into an installable "feature". (Which is also confusing, that a "feature" consists of a set of plugins. As a navive person I would expect a plugin to have multiple features).

  2. Eclipse users think of "plugins" at a higher level of granularity. If you go to, there are over 1000 "plugins" to install. But those plugins usually consist of multiple OSGi plugins and installable features...

You often hear: "Oh, if found this new and cool eclipse plugin, you should install it and try it". In this case the speaker rarely means a single OSGi plugin, but an "eclipse extension". If you hear: "My plugin depends on plugin", we are talking about OSGi plugins.

Therefore it can be very confusing to talk about "plugins". And I think "user plugins" should be called eclipse extensions or add-ins or something that can not be confused with technical plugins.

Any ideas how to resolve this confusion?

Wednesday, January 11, 2006

Future Trends (for C/C++): AOP and MDSD...

I think two trends will change the way we develop software in the future: Aspect Oriented Programming (AOP) and Model Driven Software Development (MDSD). Being an OO programmer for 20 years and working on Java and eclipse, that's not surprising. Eclipse hosts the AspectJ project and there is a AspectC/C++ plugin. The eclipse Generative Model Transformer project (GMT) is an interesting research ground for MDSD. OpenArchitectureWare also provides eclipse plugins for MDSD.

However, most of the programmers that only develop in C have no clue what's coming. It might sound for them like another hype (similar to OOP) and they feel it won't change their world because it's so far away and esoteric. But AOP and MDSD is closer to their world than they think. In some sense AOP and MDSD act like an "advanced" C preprocessor. Adding "aspects" today is often done #ifdefs and complex macros are used to "generate" code. Those lost in #ifdes and #defines might find it helpful to get new tools at their hand that allow them to do what they always did but at a higher level....