Over a million developers have joined DZone.

Effective Eclipse: Fix it, Quickly

DZone's Guide to

Effective Eclipse: Fix it, Quickly

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

You are in trouble, red lines are everywhere. There is no easy way out, so you just either start googling what went wrong, or start a copy&pasting session. If it is so smart, it can tell me that I have an error in my code, why cannot it just fix it?

Let me introduce you to a powerful ally: Quick Fix.

A small example


On the image above is a well-known situation. The method is throwing a checked exception, so the calling method must either enclose it in a try-catch block, or rethrow it. A typical solution to this problem is to manually write the try-catch block or throws clause. But there is a better way, the way of quick fix.

It can be invoked in two ways

  • clicking on the bulb, left of the line number
  • hitting CTRL + 1 - the preffered way

The result will be..


..that quick fix will propose you both fixes. In the yellow box is a preview, it looks messy, but the code will be properly formatted. If you don't like the generated code, you can change it under Window->Preferences->Java->Code Style->Code Templates. I don't like the default e.printStackTrace(), so I changed the Catch block body template to

logger.severe("Exception caught: " + ${exception_var});

Whenever a red line appears, quick fix can eliminate it. It is applicable not only to the situation above, it can fix:

  • Typos

  • Imports

  • Casting

    Starting with the simple casts...


    .. and even more intricate


    .. resulting in

  • and any other kind of problem I am unable to think up at the moment.

I found quick fix helpful even in the desperate situations like this one:


Project needs to migrate WTP metadata? Ok then, have your fun.


When there is nothing to fix, quick fix turns itself to a quick refactoring. Let's see what will it propose on our list.


See, it provides all sorts of context sensitive advices. Refactoring, renaming, annotations, everything is there, hidden under one shortcut key. A powerful shortcut key, definitely.

The quick fix feature can be even used to reduce typing. Imagine we call a method join(), which returns a Set<SortedSet<Item>> and we want to store the return value in a variable. If you did not run after seeing that behemont, you can let quick fix do the hard work.


Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}