View | Details | Raw Unified | Return to bug 157847 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/util/BindingKeyResolver.java (-2 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
2
 * Copyright (c) 2005, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 435-441 Link Here
435
			case Wildcard.EXTENDS:
435
			case Wildcard.EXTENDS:
436
			case Wildcard.SUPER:
436
			case Wildcard.SUPER:
437
				BindingKeyResolver boundResolver = (BindingKeyResolver) this.types.get(0);
437
				BindingKeyResolver boundResolver = (BindingKeyResolver) this.types.get(0);
438
				this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, (TypeBinding) boundResolver.compilerBinding, null /*no extra bound*/, kind);
438
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847, do not allow creation of
439
				// internally inconsistent wildcards of the form '? super <null>' or '? extends <null>'
440
				this.typeBinding = boundResolver.compilerBinding == null ? null : this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, (TypeBinding) boundResolver.compilerBinding, null /*no extra bound*/, kind);
439
				break;
441
				break;
440
			case Wildcard.UNBOUND:
442
			case Wildcard.UNBOUND:
441
				this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, null/*no bound*/, null /*no extra bound*/, kind);
443
				this.typeBinding = this.environment.createWildcard((ReferenceBinding) this.typeBinding, this.wildcardRank, null/*no bound*/, null /*no extra bound*/, kind);
(-)src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java (+89 lines)
Lines 2133-2137 Link Here
2133
			element
2133
			element
2134
		);
2134
		);
2135
	}
2135
	}
2136
	/**
2137
	 * Test behavior when the binding key denotes a non existent type.
2138
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847" 
2139
	 */
2140
	public void test157847a() throws CoreException {
2141
		String filePath = "/P/src/Bug157847A.java";
2142
		try {
2143
			String contents =
2144
				"public class Bug157847A<T> {\n" +
2145
				"	void add(Y<? extends T> l) {}\n" +
2146
				"}\n"+
2147
                "interface Y<T> {}\n";
2148
			createFile(filePath, contents);
2149
2150
			BindingRequestor requestor = new BindingRequestor();
2151
			String[] bindingKeys = new String[] {"LBug157847A~ThisTypeDoesNotExist;"};
2152
			resolveASTs(
2153
				new ICompilationUnit[] {},
2154
				bindingKeys,
2155
				requestor,
2156
				getJavaProject("P"),
2157
				this.workingCopy.getOwner()
2158
			);
2159
			IBinding[] bindings = requestor.getBindings(bindingKeys);
2160
			assertTrue("Constructed non existing type", bindings.length == 0);
2161
		} finally {
2162
			deleteFile(filePath);
2163
		}
2164
	}
2165
	/**
2166
	 * Ensures that we don't create internally inconsistent wildcard
2167
	 * bindings of the form '? extends <null>' or '? super <null>'
2168
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847" 
2169
	 */
2170
	public void test157847b() throws CoreException {
2171
		String filePath = "/P/src/Bug157847B.java";
2172
		try {
2173
			String contents =
2174
				"public class Bug157847B<T> {\n" +
2175
				"	void add(Y<? super T> l) {}\n" +
2176
				"}\n"+
2177
                "interface Y<T> {}\n";
2178
			createFile(filePath, contents);
2179
2180
			BindingRequestor requestor = new BindingRequestor();
2181
			String[] bindingKeys = new String[] {"LBug157847B~Y<LBug157847B~Y;{0}-!LBug157847B;{0}*54;>;"};
2182
			resolveASTs(
2183
				new ICompilationUnit[] {},
2184
				bindingKeys,
2185
				requestor,
2186
				getJavaProject("P"),
2187
				this.workingCopy.getOwner()
2188
			);
2189
			IBinding[] bindings = requestor.getBindings(bindingKeys);
2190
			assertTrue("Constructed bogus wildcard", bindings.length == 0);
2191
		} finally {
2192
			deleteFile(filePath);
2193
		}
2194
	}
2195
	/**
2196
	 * Ensures that we don't create internally inconsistent wildcard
2197
	 * bindings of the form '? extends <null>' or '? super <null>'
2198
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=157847" 
2199
	 */
2200
	public void test157847c() throws CoreException {
2201
		String filePath = "/P/src/Bug157847C.java";
2202
		try {
2203
			String contents =
2204
				"public class Bug157847C<T> {\n" +
2205
				"	void add(Y<? extends T> l) {}\n" +
2206
				"}\n"+
2207
                "interface Y<T> {}\n";
2208
			createFile(filePath, contents);
2209
2210
			BindingRequestor requestor = new BindingRequestor();
2211
			String[] bindingKeys = new String[] {"LBug157847C~Y<LBug157847C~Y;{0}+!LBug157847C;{0}*54;>;"};
2212
			resolveASTs(
2213
				new ICompilationUnit[] {},
2214
				bindingKeys,
2215
				requestor,
2216
				getJavaProject("P"),
2217
				this.workingCopy.getOwner()
2218
			);
2219
			IBinding[] bindings = requestor.getBindings(bindingKeys);
2220
			assertTrue("Constructed bogus wildcard", bindings.length == 0);
2221
		} finally {
2222
			deleteFile(filePath);
2223
		}
2224
	}
2136
2225
2137
}
2226
}

Return to bug 157847