Bug 94212 - Cannot set method breakpoint in generics
Summary: Cannot set method breakpoint in generics
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P2 normal (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Kevin Barnes CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-09 19:25 EDT by Luc Bourlier CLA
Modified: 2006-03-20 08:45 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luc Bourlier CLA 2005-05-09 19:25:58 EDT
public interface IGen<T> {
  T foo(T t);
}

When I try to add a method breakpoint on foo, I get an error logged : 
'Source method signature could not be resolved'
Comment 1 Darin Wright CLA 2005-05-09 21:58:55 EDT
The error is misleading - but we don't support breakpoints on interfaces.
Comment 2 Luc Bourlier CLA 2005-05-10 13:40:46 EDT
I get the same problem in a class.

public class TestGen<T> {
	T foo() {
		return null;
	}
}
Comment 3 Darin Wright CLA 2005-05-13 14:08:45 EDT

*** This bug has been marked as a duplicate of 94903 ***
Comment 4 Markus Keller CLA 2005-08-19 05:41:31 EDT
This bug seems not to be a dup of bug 94903, since I can still reproduce in
I20050816-1235.

The problem is the type variable T in the signature of T foo().
Comment 5 Kevin Barnes CLA 2006-03-07 15:41:30 EST
When trying to create a method entry breakpoint on a method that returns a type variable it appears that the resolved method signature return from jdt core is incorrect. 
For the method "X foo(int index)" method.getSignature return "(I)QX;". We expected it to return (I)TX;"

Moving to jcore for comment.

My sample code is this:
public class FooList<X> extends ArrayList<X> {
	X foo(int index) {
		return super.get(index);
	}
	
	
	public static void main(String[] args) {
		FooList<String> fooList = new FooList<String>();
		fooList.add("one");
		fooList.foo(0);
	}
}
Comment 6 Jerome Lanneluc CLA 2006-03-08 07:13:16 EST
IMethod#getSignature() is not supposed to return resolved info. Only the DOM AST could help you in this case.

Do you need the parameter X in this case, or do you need Object (its erasure) found in the .class file (and maybe returned by JDI) ? 
Comment 7 Darin Wright CLA 2006-03-08 09:12:15 EST
Jerome, comment#5 was not completely accurate, we are using:

   IType.resolve(String name)

The IType is the "SourceType" FooList and the name we are passing in is "X". In this case it should return a resolved type? (it returns null).
Comment 8 Jerome Lanneluc CLA 2006-03-08 09:17:33 EST
Unfortunately, IType#resolveType(...) takes a type name, not a type parameter name.
Comment 9 Darin Wright CLA 2006-03-08 09:27:41 EST
Note: the VM/JDI returns the following as the method's siganture:

(I)Ljava/lang/Object;

So, we will not match on TX either.
Comment 10 Darin Wright CLA 2006-03-08 09:52:25 EST
Fixed in ToggleBreakpointAdapter. When type cannot be resolved we then check against the type's type parameters for a match and resolve to Object when the name matches.
Comment 11 Darin Wright CLA 2006-03-08 09:53:07 EST
Please verify, Kevin.
Comment 12 Markus Keller CLA 2006-03-08 10:14:25 EST
I don't know your code and I have not looked at the fix, but it sounds like you would assume that the erasure of a type variable is always Object. This is e.g. not the case here:

public class FooList<X extends Number> extends ArrayList<X> {
        X foo(int index) {
                return super.get(index);
        }
}
Comment 13 Kevin Barnes CLA 2006-03-09 12:13:59 EST
verified
Comment 14 Markus Keller CLA 2006-03-20 08:45:54 EST
I filed bug 132543 for comment 12.