Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 334662

Summary: NullPointerException inspecting variable
Product: [Eclipse Project] JDT Reporter: John Peberdy <john>
Component: DebugAssignee: Michael Rennie <Michael_Rennie>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: curtis.windatt.public
Version: 3.7Flags: curtis.windatt.public: review+
Target Milestone: 3.7 M7   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
fix none

Description John Peberdy CLA 2011-01-18 10:49:47 EST
Build Identifier: Build id: I20090611-1540

When suspended in a particular method in a anonymous class inside a static block a NPE is thrown whenever trying to add a watch expression or inspect.

static {
s_map.put(foo, new Function() {public void run(..)
   expressions <<<Suspend here

})
}

java.lang.NullPointerException
at org.eclipse.jdt.internal.debug.eval.ast.engine.SourceBasedSourceGenerator.endVisit(SourceBasedSourceGenerator.java:834)
at org.eclipse.jdt.core.dom.ClassInstanceCreation.accept0(ClassInstanceCreation.java:337)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2551)
at org.eclipse.jdt.core.dom.MethodInvocation.accept0(MethodInvocation.java:245)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2528)
at org.eclipse.jdt.core.dom.ExpressionStatement.accept0(ExpressionStatement.java:144)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2551)
at org.eclipse.jdt.core.dom.Block.accept0(Block.java:136)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2528)
at org.eclipse.jdt.core.dom.Initializer.accept0(Initializer.java:250)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2551)
at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:484)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2551)
at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:219)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2480)
at org.eclipse.jdt.internal.debug.eval.ast.engine.EvaluationSourceGenerator.createEvaluationSourceFromSource(EvaluationSourceGenerator.java:152)
at org.eclipse.jdt.internal.debug.eval.ast.engine.EvaluationSourceGenerator.getSource(EvaluationSourceGenerator.java:213)
at org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine.getCompiledExpression(ASTEvaluationEngine.java:226)
at org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine.evaluate(ASTEvaluationEngine.java:115)
at org.eclipse.jdt.internal.debug.ui.JavaWatchExpressionDelegate$EvaluationRunnable.run(JavaWatchExpressionDelegate.java:144)
at org.eclipse.jdt.internal.debug.core.model.JDIThread$ThreadJob.run(JDIThread.java:2751)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)


Reproducible: Always
Comment 1 Michael Rennie CLA 2011-04-05 15:46:20 EDT
Created attachment 192593 [details]
fix

The problem was that we did not handle the Initializer case for an enclosing element *and* we had no check to make sure we have not run off the top of the parent chain (parent node == null).

The patch handles both cases and provides unit tests for handling inspect evals in anonymous types.
Comment 2 Michael Rennie CLA 2011-04-05 15:47:40 EDT
Applied patch to HEAD, please verify Curtis
Comment 3 Curtis Windatt CLA 2011-05-04 16:46:50 EDT
Verified.