Checklipse: Finding Bugs in Eclipse Code using Eclipse


Overview

Checklipse is a tool designed to help Eclipse developers find some common error patterns in their code before the code is deployed. Checklipse uses lightweight static analysis of Java sources to detect potential errors. The errors are then presented to the user for review.

The goal of Checklipse is to help core Eclipse developers as well as plugin authors find serious errors in their code. We are currently seeking feedback from Eclipse developers on whether the tool is useful and how many errors it pinponts are actually serious. A beta version of Checklipse is available for download and we would be happy to hear about your experience with it.

Documentation

For more information about Checklipse and the bugs we have found with it, please refer to a short paper we have written on this subject.

Error Patterns

The following types of errors are currently detected by Checklipse:
    Failing to call super.
    In many cases, Eclipse APIs mandate calling super.m(..) when implementing method m in a subclass. When subclassing Eclipse components such as ViewPart, etc. programmers often forget to call super.m(...) on all execution paths through m. This can lead to errors later in program execution.

    Failing to clear collections in dispose.
    Method dispose defined in many classes in Eclipse code is commonly used to releases whatever resources the current object may be referring to. Doing so allows the garbage collector For more on SWT resource management, refer to "SWT: The Standard Widget Toolkit. PART 2: Managing Operating System Resources" and "User interface resources".
  • Failing to remove listeners.
    Listeners are commonly used in GUI code to register handlers for GUI events. Failing to remove listeners when GUI components are deallocated can result in memory leaks and, over time, application instability and crashes. Subclasses of ViewPart are supposed to register listeners in method createViewPart and un-register them in dispose. Checklipse tries to match calls that register and remove listeners to make sure all have been properly removed. More information about this error pattern can be found in a book called "Bitter Java". A chapter of the book on memory management errors in Java is available online.

We are looking for more common error patterns to check for in Eclipse code; please feel free to make suggestions.

Using the Tool

Checklipse is implemented as an Eclipse plugin that uses AST information provided by the JDT to analyze Eclipse sources. Extract the plugin into your Eclipse directory and load Eclipse plugins you are interested in checking into your workspace. Most recent versions of plugins that come with Eclipse can be obtainted from the Eclipse CVS repository at dev.eclipse.org.

To make sure that Checklipse is installed properly, go to Window|Show view|Other and make sure that you have a group called Checklipse in the list. This group should look like this:

Checklipse displays the information it discovers about Eclipse and user-provided plugins in three specialized viewers shown below.

Extend super viewer

The first column lists methods that fail to call dispose. The second "category" column lists the rule being violated. For example, the first row says Platform.stop reimplements org.eclipse.core.runtime.Plugin.stop.

Dispose viewer

For each class implementing method dispose we list all member contaners (such as Maps and Vectors). In the screenshot below, member fContextSubmissions is not cleared in method dispose. To help determine if this may ideed lead to resource leaks, the uses of fContextSubmissions in the same class are listed in blue. For example, examiling the highlighted call to fContextSubmissions.put reveals that the first argument of put is of type ILaunch. This suggests that classes implementing intefrace ILaunch may leak because of being put into map fContextSubmissions.

Lapsed listener viewer

The lapsed listener viewer shows calls related to listener registration and un-registration. Matched calls to addPartListener and removePartListener in AbstractInfoVieware shown in green. the call to addSelectionListener in TableWithTotalView is not matched with anything because that class is missing method dispose.

Download

A beta version of Checklipse is available for download. It is compatible with Eclipse version 3.1.

Checklipse sources are available from SourceForge.

Contact

We are looking for ideas on how to make Checklipse better. Please feel free to ask questions and make suggestions about the tool. Contact Benjamin Livshits via email.


Stanford SUIF Group

Last modified on 12/21/05. [Home]