Community
Participate
Working Groups
class A{ void f(){ A a= new A(); a.clone(); //resolving the name fails - returns null } }
happens also if you do add throws CloneNotSupportedException to the declaration of f
I will investigate.
Do you mean resolving "a" or "clone"? I tried "a" and I have no problem with this source: void f() throws CloneNotSupportedException { A a= new A(); a.clone(); }
sorry, i meant resolving clone (that's the 'call to a protected superclass method' from the summary)
I have no problem to resolve "clone" as well. I will try without the throws clause.
Both cases work fine. Could you please give me your code?
Could not reproduce so far. Please provide additional steps. I tried to resolve: class A{ void f(){ A a= new A(); a.clone(); //resolving the name fails - returns null } } And I got a binding for the name "clone" in a.clone();
sorry, my bad here's the original cu (it does have a compile error): so, lower priority because of that error. however, F3 resolves it correctly ----------A.java ------- package p; class A{ public void foo(){}; } class Test{ void test() throws CloneNotSupportedException{ A a= new A(); a.clone(); } } ----------A.java -------
It is not possible to get this binding, because the method is not visible. So in fact I have a problem binding from the compiler's world. null is returned because before returning the new binding I check first if it is a valid binding. In this case, it is not a valid binding. I really don't see how I could create a valid binding in this very specific case.
how come F3 works?
I don't know. Which binding would you expect? The methodbinding that correspond to the method clone() in java.lang.Object? I can try to hack the resolution to return this binding.
Object::clone() is the one - the method is just not accessible from there. but the compiler knows which one it is. anyway - like i said, this PR is of lower priority for me because there is a compilation error. so, if you see difficulties - feel free to close. (i might reopen at some point, though - who knows :-) )
I can return the Object::clone(). I simply need to check the problemId(). It is only when the problem id is NotVisible that I can retrieve the method binding by getting the binding through the declaring class. This code needs more testing, but it should be released quite soon.
Object::clone() is returned in this example. More generally, the binding is retrieved from the problem binding when the problemReason is NotVisible and in this case only, otherwise null is returned. Fixed and released in 2.1 stream.
I confirm, this is the trick we play in code-select. We also provide a fuzzy match in case a method isn't applicable (best match found if any), but I am not convinced this should work. Anyhow, providing a binding in presence of an error is ok, but as long as the error isn't ignored. Ok, Adam ?
any API easy way to find out that the method is not visible ? (i mean, without doing all the checks myself)
I don't see the need of an API if we report the error in the compilation unit problems' list and we give your the proper binding. This should be a workable solution.
Verified.