14 Dec 2004 derupe   » (Journeyer)

Eclipse QuickFix problem

Encountered a strange problem while working on Eclipse [In the latest integration build - Version: 3.1.0 Build id: 200412081200]

I wrote a small snippet of code -

    if(getContentSpec().equals("Test"))
        return true;
The method getContentSpec was not implemented in the class; so it gave a compilation error. I took the QuickFix route and asked Eclipse to generate the stub for me. To my surprise, it generated the following code -
/**
* @return
*/
private AbstractList getContentSpec() {
    // TODO Auto-generated method stub
    return null;
}
I didn't really expect the method to return a String - but I at least expected it to return an Object. But it ended by returning an AbstractList!!!!! This was s t r a n g e!

To recreate the problem, before I submit the bug, I created a simple class -

public class QuickFixEquals {

public boolean hasChildren() { return(getContentSpec().equals("Test")); } }

Applied QuickFix ... and the code generated was
    private Object getContentSpec() {
        // TODO Auto-generated method stub
        return null;
    }
Well, thats what I wanted in the original code ... why did it behave differently here?

I finally tracked it down to ... guess what? ... an import statement.

Try QuickFix on the following code

import java.util.List;

public class QuickFixEquals {

public boolean hasChildren() { return(getContentSpec().equals("Test")); } }

It will generate
	private List getContentSpec() {
		// TODO Auto-generated method stub
		return null;
	}
Better yet, try this code
import java.util.ArrayList;
import java.util.List;

public class QuickFixEquals {

public boolean hasChildren() { return (getContentSpec().equals("Test")); }

public List<String> getList() { return new ArrayList<String>(); } }

Apply QuickFix, and lo, you get -
    private AbstractList<E> getContentSpec() {
        // TODO Auto-generated method stub
        return null;
    }
Here's the link to the QuickFix Bug.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!