### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/VariableBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/VariableBinding.java,v retrieving revision 1.56 diff -u -r1.56 VariableBinding.java --- dom/org/eclipse/jdt/core/dom/VariableBinding.java 24 Oct 2007 13:50:52 -0000 1.56 +++ dom/org/eclipse/jdt/core/dom/VariableBinding.java 13 Dec 2007 15:18:50 -0000 @@ -199,6 +199,7 @@ IMethodBinding declaringMethod = getDeclaringMethod(); if (declaringMethod == null) return null; JavaElement method = (JavaElement) declaringMethod.getJavaElement(); + if (method == null) return null; if (!(this.resolver instanceof DefaultBindingResolver)) return null; VariableDeclaration localVar = (VariableDeclaration) ((DefaultBindingResolver) this.resolver).bindingsToAstNodes.get(this); if (localVar == null) return null; #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java,v retrieving revision 1.53 diff -u -r1.53 ASTModelBridgeTests.java --- src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java 12 Dec 2007 09:25:23 -0000 1.53 +++ src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java 13 Dec 2007 15:18:53 -0000 @@ -150,6 +150,12 @@ "}" }, "1.5"); + setUpWorkingCopy(); + } + + private void setUpWorkingCopy() throws JavaModelException { + if (this.workingCopy != null) + this.workingCopy.discardWorkingCopy(); IProblemRequestor problemRequestor = new IProblemRequestor() { public void acceptProblem(IProblem problem) {} public void beginReporting() {} @@ -1354,6 +1360,37 @@ } /* + * Ensures that the IJavaElement of an IBinding representing a local variable in an anonymous type + * in a discarded working copy is null. + * (regression test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=212096 ) + */ + public void testLocalVariable4() throws JavaModelException { + try { + ASTNode node = buildAST( + "public class X {\n" + + " void foo() {\n" + + " new Object() {\n" + + " void bar() {\n" + + " int /*start*/local/*end*/;\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + ); + IBinding binding = ((VariableDeclaration) node).resolveBinding(); + this.workingCopy.discardWorkingCopy(); + IJavaElement element = binding.getJavaElement(); + assertEquals( + "Unexpected Java element", + null, + element + ); + } finally { + setUpWorkingCopy(); + } + } + + /* * Ensures that the IJavaElement of an IBinding representing a member type is correct. */ public void testMemberType() throws JavaModelException {