My Blog

Welcome! What is this blog for/What will be blogged here? Well, frankly, only time will tell that ... ;-) The plan is to have stuff like ... what I plan to do/Interesting things that I want to share. My interests and hobbies ... and what I'm doing/not doing for it. Random thoughts/Opinions. Just about anything I feel like writing! have fun!

Tuesday, December 14, 2004

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.

0 Comments:

Post a Comment

<< Home