Community
Participate
Working Groups
build 20021113 I have some test code that contains an anonymous subclass. Whenever I try to select code in the context of one of its methods and evaluate it using snippet evaluation, it throws a NPE. The NPE happens while visiting a MethodInvocation node in the AST. The visitor calls "methodBinding = node.getName().resolveBinding()", and this returns null. Then it calls "containsAsLocalType(methodBinding), which tries to invoke a method on methodBinding, but it is null, hence the NPE. I have not been able to construct a simple test case. To reproduce my scenario: Checkout the following from dev.eclipse.org: org.apache.ant org.apache.xerces org.eclipse.ant.core org.eclipse.core.boot org.eclipse.core.resources org.eclipse.core.resources.win32 org.eclipse.core.runtime org.eclipse.core.tests.harness org.eclipse.core.tests.resources org.eclipse.platform org.junit Put a breakpoint in the method "wasSuccess" in the anony inner class inside org.eclipse.core.tests.resources.LinkedResourceTest#testMoveFile. Use PDE Junit to launch the test LinkedResourceTest. When the breakpoint is hit, step a couple of times, and then try to evaluate the expression "destination.exists()". It will then NPE.
Luc, can you comment on this one (do we support this scenario?)
The evaluation in this context is not currently supported, but we should handle the case (i.e. display an error message, not a NPE). The problem is the String passed as parameter when the anonymous type is created. The evaluation in the context of an anonymous class which has no default constructor (constructor with no parameter) is not supported. a smaller test case : public class Bug_26159_1 { static class Inner { Inner(String s) { test(); } void test() { System.out.println("Inner"); } } public static void main(String[] args) { new Inner("test") { void test() { System.out.println("Anonymous"); // <--- breakpoint here } void print() { System.out.println("Anonymous"); } }; } I have may be a way to allow the evaluation in this context, I will test.
Marking as M4 candidate.
I modified SourceBaseSourceGenerator to handle this case. An error message is now returned, informing that this case is currently no supported. changes in SourceBaseSourceGenerator and EvaluationSourceGenerator.
Closing this bug. I entered bug 28315 for the support of the evaluation in this case. Please verify (DarinW)
Verified.