Bug 81544 - [dom] java.util.List<URL> sometimes has a binding, sometimes not
Summary: [dom] java.util.List<URL> sometimes has a binding, sometimes not
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 84585
Blocks:
  Show dependency tree
 
Reported: 2004-12-17 12:41 EST by Markus Keller CLA
Modified: 2008-05-08 09:37 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2004-12-17 12:41:33 EST
I20041216-2000

package p;
class Bindings {
	java.util.List<URL> method(java.util.List<URL> list) {
		java.util.List<URL> url= new java.util.List<URL>();
		return url;
	}
}

The ParameterizedType "java.util.List<URL>" sometimes has a binding, sometimes
not. In the example above, all references to "java.util.List<URL>" have a
generic binding for List<E>, except the method parameter type, which has a null
binding.

Up to now, bindings were either correct, or null iff not resolvable. I would
expect to get null for all references to "java.util.List<URL>".
Comment 1 Olivier Thomann CLA 2005-02-02 13:14:59 EST
Do you have java.net.URL as an import? If not, it can make sense that the type
cannot be resolved.
Comment 2 Olivier Thomann CLA 2005-02-02 13:28:49 EST
I added a regression test to check that all qualified names, simple names,
qualified types, simple types and parameterized types have a binding if
java.net.URL is resolved.
Can you please confirm that this is your test case? If you don't import
java.net.URL, you cannot expect all bindings to be resolvable.
Comment 3 Olivier Thomann CLA 2005-02-02 13:51:39 EST
Ok, looking at 81101, it seems that URL is not imported. Therefore we do the
best we can to provide you with some bindings.
Comment 4 Olivier Thomann CLA 2005-02-02 13:55:30 EST
Kent, is it possible to get a binding for the method and for its parameters in
this case if URL is not imported.
The DOM/AST bindings cannot return any value for the parameter, because it has
no compiler binding.
Kent, why do we get a return type binding?
Comment 5 Kent Johnson CLA 2005-02-02 15:51:41 EST
Because we check the parameter types first & fail. The parameter binding is 
null because it cannot be resolved.

We did not bother to null out the return type's binding in this case but we 
can if you want us to... we don't need to for normal compilation.
Comment 6 Kent Johnson CLA 2005-02-02 16:04:06 EST
Actually the MethodDeclaration's return type is a TypeReference (which knows 
about List).

The MethodDeclaration's arguments are Argument nodes that know about the 
TypeReference (which knows about List).

You have everything you need to answer List back in both cases.
Comment 7 Olivier Thomann CLA 2005-02-02 16:08:06 EST
ok, I take it back. Thanks.
Comment 8 Olivier Thomann CLA 2005-02-02 17:51:28 EST
Fixed and released in HEAD.
The resolved type of the type reference was wrongly reset to null in the bind of
argument. Therefore I didn't have the binding when converting the code.
Added a regression test to check that all parameterized type returns a binding
java.util.List<E>.
Only the name for the method selector and occurences of URL don't have a binding.
Comment 9 Markus Keller CLA 2005-02-07 04:26:22 EST
Sorry, I was away and couldn't answer your questions in time. Unfortunately, the
solution in HEAD does not match our expectations.

As I said in comment 0, "java.util.List<URL>" should have 'null' as binding, and
not 'List<E>' (without an import statement for "URL"). References to generic
types should never be of kind #isGenericType().

Either a type binding should be correct, or it should be absent. Otherwise, it's
getting hard to deal with code like "java.util.List<java.util.ArrayList<URL>>",
where you never know what's really resolved and what's not.
Comment 10 Olivier Thomann CLA 2005-02-07 09:51:20 EST
If I nullify the binding in this case, it will also be null in cases where you
want a binding to be returned. I can nullify the binding as soon as the binding
is not a valid binding (problem bindings). But you will lose bindings in cases
the code is illegal.
From the binding resolver perspective, there is no difference.
Comment 11 Dirk Baeumer CLA 2005-02-07 10:21:15 EST
For me this depends on clients:

- refactoring: in allmost all cases refactoring isn't interrested in guessed 
  bindings
- quick fix: will be interested in guessed bindings.

So I would opt for having a flag on ASTParser to control this. The default
should be to not guess bindings.
Comment 12 Olivier Thomann CLA 2005-02-07 11:16:21 EST
We need a consistent way to get the binding. The resolved type is set to be a
generic type binding and it is not tagged as an invalid binding. So I cannot fix
it on the DOM/AST side if I don't have more information.
It should either be a problem binding, or it should be null.
Comment 13 Philipe Mulet CLA 2005-02-07 11:42:09 EST
Compiler issue can be resolved in this case.
I would propose that partial matches are nulled out (like here where no argument
was bound), due to inconsistencies. But if non visible etc... it would remain
connected.

BTW - isn't the AST tagged with having problems anyway ? 
Comment 14 Olivier Thomann CLA 2005-02-07 11:46:58 EST
We investigate if we can nullify the binding in the case. But it would be null
all the time.
Comment 15 Dirk Baeumer CLA 2005-02-07 12:08:10 EST
As said in #11 the behaviour should be controllable via a flag. Quick fix for
example would be interested in this. Alternatively we can think about annotating
the binding itself. But this might cause problems with existing clients which
assume that null is returned from resolveBinding in the case it isn't accurate.
Comment 16 Martin Aeschlimann CLA 2005-02-08 03:57:23 EST
I support Dirks comment 15. 'Null' would hurt quick fix quite a lot.
I would like to offer quick fixes for mismatching type parameters, e.g. too many
or not enough type parameters, similar to mismatching method arguments.
(remove type arguments, add type parameter to type...)

In 'List<String, String>' having not even a binding to List would be tough.
A generic binding is better than nothing, but what maybe would be a good idea is
to attach some 'erasured' binding like List<Object> to it.

To distiguish guessed bindings from correct bindings, would it maybe make sense
to have a new API 'isGuessed' to IBinding? (or 'isProblemBinding'). 




Comment 17 Olivier Thomann CLA 2005-02-08 10:02:56 EST
The compiler doesn't always create problem bindings when it knows that the
binding won't be used later.
So for performance reason, I won't push to add an API for this.
The actual behavior is acceptable for me.
Comment 18 Dirk Baeumer CLA 2005-02-08 10:45:56 EST
Olivier, can you outline the performance problems and what you mean by "actual
behaviour". The whole PR complains about the actual behaviour.
Comment 19 Olivier Thomann CLA 2005-02-08 10:56:30 EST
The performance problem is simple. In this case, the compiler doesn't need to
carry the binding for invalid type. Creating a problem binding each time such a
case occurs would penalize the compiler.
I can change the actual behavior to get a binding for all occurences of
java.util.List<URL>. But I cannot get null for all occurrences in one case and
not null in the other case.
For your information, the binding I am getting is not a problem binding. So from
the converter point of view, I cannot make the distinction between a valid
binding and this invalid case.
Comment 20 Olivier Thomann CLA 2005-02-08 11:33:55 EST
Ok, I'll do what Philippe suggests in comment 13.
If the argument cannot be resolved, the dom binding will always be null.
If this is simply a visibility issue, then a binding will be returned.
This would make the resolution of java.util.List<URL> consistent in all cases.
Comment 21 Olivier Thomann CLA 2005-02-08 12:10:12 EST
Fixed and released in HEAD.
Regression test added in ASTConverter15Test.test0138.
Comment 22 Olivier Thomann CLA 2005-02-08 13:41:47 EST
Need further investigation.
Comment 23 Olivier Thomann CLA 2005-06-06 22:48:21 EDT
In HEAD right now, the binding is always the generic type java.util.List<E>.
Is this ok for you?
If yes, I would close this one.
Comment 24 Martin Aeschlimann CLA 2005-06-07 03:06:56 EDT
This is good from the quick fix side.
Comment 25 Markus Keller CLA 2005-06-07 03:13:53 EDT
The current solution conflicts with bug 80472. When I get a generic binding, I
don't know whether it's generic because of bug 80472 or because type arguments
could not be resolved. I think we can ship 3.1 with the current solution, but
this should definitely be discussed again for 3.2.
Comment 26 Olivier Thomann CLA 2005-06-07 08:35:33 EDT
Because URL cannot be resolved, we end up with a generic type binding.
The point of this PR was that the resolution was inconsistent. This is not the
case anymore.
Comment 27 Markus Keller CLA 2005-06-07 10:37:14 EDT
OK to close this bug then. Will use bug 84585 for further discussions about
partly unresolved bindings.
Comment 28 Olivier Thomann CLA 2005-06-07 10:44:29 EDT
Close as WORKSFORME.
Regression test is org.eclipse.jdt.core.tests.dom.ASTConverter15Test.test0138.
A fix has been done for another problem. No specific changes for this PR.
Comment 29 Olivier Thomann CLA 2008-05-08 09:37:52 EDT
I had to adjust a regression test for this bug when fixing bug 230127, because you can only get a binding for URL in java.util.List<URL>, if the binding recovery is on.