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(){
super.foo();
doSomethingStupid();
}
}
class C extends B {
protected void foo(){
super.super.foo(); // it is illegal to omit the stupid stuff of class B
doSomethingUseful();
}
}

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 A.foo() 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 super.super.foo()....

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 eclipse-dev@eclipse.org:

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) {
this.flags=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 ...id=123) 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.