Community
Participate
Working Groups
20020418 When resolving the type in a castexpression, the result is always null. (castExpression.getType().resolveBinding())
Could you please let me give me a small example? I tried: package test0303; public class Test { void foo() { char x; x = (char)3; } } But I could not reproduce it. I will try different kind of cast expression.
I tried: (java.lang.Object) "s"; (java.lang.Object[]) null; (int[]) null; (char)3; and I could not reproduce. A test case is required for further investigation.
This is my testcase: I just realized that it matters that my code is not resolvable. When fixing the code, resolving succeeds. In this code, String can not be resolved. public static void goo(Object o) { Vector s= (String) ooo; }
What is the type of the ooo variable or field? Is it a Vector? I think it makes sense that the resolution fails if the casting is incorrect. I will double-check when I got a complete test case.
I'm working on quick fix. 'ooo' is an undefined variable, and I try to resolve the type in the cast (String) to see if 'ooo' can be 'Object' or 'int' (depending on the cast). I was hoping that the unresolvable 'ooo' would not influence the resolving of the typebinding of the cast. However, this is a minor thing, don't spend too much time on it.
The unresolved name causes the cast expression to have a problem binding. Then when you request the resolution of the type, you end up with null. This is normal. There is no garantee that the binding resolution can succeed with incorrect code. And in this case we cannot do better. Ok to close?
This is not a bug. When the binding resolution cannot complete, the resolveBinding() method returns null. Closed.