Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 26159 - NPE evaluating snippet in anonymous inner class
Summary: NPE evaluating snippet in anonymous inner class
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 major (vote)
Target Milestone: 2.1 M5   Edit
Assignee: Darin Wright CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-11-13 14:21 EST by John Arthorne CLA
Modified: 2002-12-15 12:47 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Arthorne CLA 2002-11-13 14:21:31 EST
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.
Comment 1 Darin Wright CLA 2002-11-13 14:30:08 EST
Luc, can you comment on this one (do we support this scenario?)
Comment 2 Luc Bourlier CLA 2002-11-13 16:29:06 EST
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.
Comment 3 Darin Wright CLA 2002-11-13 16:47:31 EST
Marking as M4 candidate.
Comment 4 Luc Bourlier CLA 2002-12-02 16:46:08 EST
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.
Comment 5 Luc Bourlier CLA 2002-12-13 23:16:21 EST
Closing this bug.
I entered bug 28315 for the support of the evaluation in this case.

Please verify (DarinW)
Comment 6 Darin Wright CLA 2002-12-15 12:47:06 EST
Verified.