### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java,v retrieving revision 1.55 diff -u -r1.55 BindingKeyResolver.java --- model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java 7 Mar 2009 00:58:54 -0000 1.55 +++ model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java 10 May 2010 14:36:18 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2009 IBM Corporation and others. + * Copyright (c) 2005, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -435,7 +435,14 @@ case Wildcard.EXTENDS: case Wildcard.SUPER: BindingKeyResolver boundResolver = (BindingKeyResolver) this.types.get(0); - this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, (TypeBinding) boundResolver.compilerBinding, null /*no extra bound*/, kind); + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847, do not allow creation of + // internally inconsistent wildcards of the form '? super ' or '? extends ' + final Binding boundBinding = boundResolver.compilerBinding; + if (boundBinding instanceof TypeBinding) { + this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, (TypeBinding) boundBinding, null /*no extra bound*/, kind); + } else { + this.typeBinding = null; + } break; case Wildcard.UNBOUND: this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, null/*no bound*/, null /*no extra bound*/, kind); #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.63 diff -u -r1.63 ASTModelBridgeTests.java --- src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java 14 Dec 2009 18:46:07 -0000 1.63 +++ src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java 10 May 2010 14:36:18 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2133,5 +2133,94 @@ element ); } + /** + * Test behavior when the binding key denotes a non existent type. + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847" + */ + public void test157847a() throws CoreException { + String filePath = "/P/src/Bug157847A.java"; + try { + String contents = + "public class Bug157847A {\n" + + " void add(Y l) {}\n" + + "}\n"+ + "interface Y {}\n"; + createFile(filePath, contents); + + BindingRequestor requestor = new BindingRequestor(); + String[] bindingKeys = new String[] {"LBug157847A~ThisTypeDoesNotExist;"}; + resolveASTs( + new ICompilationUnit[] {}, + bindingKeys, + requestor, + getJavaProject("P"), + this.workingCopy.getOwner() + ); + IBinding[] bindings = requestor.getBindings(bindingKeys); + assertTrue("Constructed non existing type", bindings.length == 0); + } finally { + deleteFile(filePath); + } + } + /** + * Ensures that we don't create internally inconsistent wildcard + * bindings of the form '? extends ' or '? super ' + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847" + */ + public void test157847b() throws CoreException { + String filePath = "/P/src/Bug157847B.java"; + try { + String contents = + "public class Bug157847B {\n" + + " void add(Y l) {}\n" + + "}\n"+ + "interface Y {}\n"; + createFile(filePath, contents); + + BindingRequestor requestor = new BindingRequestor(); + String[] bindingKeys = new String[] {"LBug157847B~Y;"}; + resolveASTs( + new ICompilationUnit[] {}, + bindingKeys, + requestor, + getJavaProject("P"), + this.workingCopy.getOwner() + ); + IBinding[] bindings = requestor.getBindings(bindingKeys); + assertTrue("Constructed bogus wildcard", bindings.length == 0); + } finally { + deleteFile(filePath); + } + } + /** + * Ensures that we don't create internally inconsistent wildcard + * bindings of the form '? extends ' or '? super ' + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847" + */ + public void test157847c() throws CoreException { + String filePath = "/P/src/Bug157847C.java"; + try { + String contents = + "public class Bug157847C {\n" + + " void add(Y l) {}\n" + + "}\n"+ + "interface Y {}\n"; + createFile(filePath, contents); + + BindingRequestor requestor = new BindingRequestor(); + String[] bindingKeys = new String[] {"LBug157847C~Y;"}; + resolveASTs( + new ICompilationUnit[] {}, + bindingKeys, + requestor, + getJavaProject("P"), + this.workingCopy.getOwner() + ); + IBinding[] bindings = requestor.getBindings(bindingKeys); + assertTrue("Constructed bogus wildcard", bindings.length == 0); + } finally { + deleteFile(filePath); + } + } }