### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java,v retrieving revision 1.268.2.2 diff -u -r1.268.2.2 ASTConverter15Test.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 3 Sep 2008 11:54:37 -0000 1.268.2.2 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 11 May 2009 14:24:22 -0000 @@ -46,7 +46,7 @@ } static { -// TESTS_NUMBERS = new int[] { 239 }; +// TESTS_NUMBERS = new int[] { 323 }; // TESTS_RANGE = new int[] { 308, -1 }; // TESTS_NAMES = new String[] {"test0204"}; } @@ -10229,4 +10229,48 @@ IMemberValuePairBinding pairBinding = memberValuePairBindings[0]; assertNull("Got a value", pairBinding.getValue()); } + + public void test0323() throws JavaModelException { + String contents = "package test0323;\n" + + "public class X {\n" + + " public void someMethod() {\n" + + " int i = /*start*/(new Integer(getId())).intValue()/*end*/;\n" + + " }\n" + + " public String getId() {\n" + + " return null;\n" + + " }\n" + + "}"; + this.workingCopy = getWorkingCopy("/Converter15/src/test0323/X.java", contents, true/*resolve*/ + ); + MethodInvocation methodCall = (MethodInvocation) buildAST(contents, workingCopy, false, true, true); + ParenthesizedExpression intValueReceiver = (ParenthesizedExpression) methodCall.getExpression(); + ParenthesizedExpression newParenthesizedExpression = (ParenthesizedExpression) ASTNode.copySubtree( + intValueReceiver.getAST(), intValueReceiver); + replaceNodeInParent(methodCall, newParenthesizedExpression); + ClassInstanceCreation constructorCall = (ClassInstanceCreation) newParenthesizedExpression.getExpression(); + constructorCall.resolveTypeBinding(); // This should not throw a NPE + IMethodBinding constructorBinding = constructorCall.resolveConstructorBinding(); + assertNull("Not null constructor binding", constructorBinding); + constructorCall = (ClassInstanceCreation) intValueReceiver.getExpression(); + constructorCall.resolveTypeBinding(); // This should not throw a NPE + constructorBinding = constructorCall.resolveConstructorBinding(); + assertNotNull("Null constructor binding", constructorBinding); + } + + // Utility method to replace "node" by "replacement" + private static void replaceNodeInParent(Expression node, Expression replacement) { + StructuralPropertyDescriptor loc = node.getLocationInParent(); + if (loc.isChildProperty()) { + node.getParent().setStructuralProperty(loc, replacement); + } + else { + List l = (List) node.getParent().getStructuralProperty(loc); + for (int i = 0; i < l.size(); i++) { + if (node.equals(l.get(i))) { + l.set(i, replacement); + break; + } + } + } + } } \ No newline at end of file #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java,v retrieving revision 1.164 diff -u -r1.164 DefaultBindingResolver.java --- dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 27 May 2008 22:24:51 -0000 1.164 +++ dom/org/eclipse/jdt/core/dom/DefaultBindingResolver.java 11 May 2009 14:24:23 -0000 @@ -662,7 +662,7 @@ if (typeBinding != null) { return typeBinding; } - } else { + } else if (astNode instanceof AllocationExpression) { // should be an AllocationExpression AllocationExpression allocationExpression = (AllocationExpression) astNode; return this.getTypeBinding(allocationExpression.resolvedType);