View | Details | Raw Unified | Return to bug 205917
Collapse All | Expand All

(-)model/org/eclipse/jdt/core/JavaCore.java (-4 / +6 lines)
Lines 2335-2347 Link Here
2335
	 * Returns the Java model element corresponding to the given handle identifier
2335
	 * Returns the Java model element corresponding to the given handle identifier
2336
	 * generated by <code>IJavaElement.getHandleIdentifier()</code>, or
2336
	 * generated by <code>IJavaElement.getHandleIdentifier()</code>, or
2337
	 * <code>null</code> if unable to create the associated element.
2337
	 * <code>null</code> if unable to create the associated element.
2338
	 * If the returned Java element is an <code>ICompilationUnit</code>, its owner
2338
	 * If the returned Java element is an <code>ICompilationUnit</code> or an element
2339
	 * is the given owner if such a working copy exists, otherwise the compilation unit
2339
	 * inside a compilation unit, the compilation unit's owner is the given owner if such a 
2340
	 * is a primary compilation unit.
2340
	 * working copy exists, otherwise the compilation unit is a primary compilation unit.
2341
	 *
2341
	 *
2342
	 * @param handleIdentifier the given handle identifier
2342
	 * @param handleIdentifier the given handle identifier
2343
	 * @param owner the owner of the returned compilation unit, ignored if the returned
2343
	 * @param owner the owner of the returned compilation unit, ignored if the returned
2344
	 *   element is not a compilation unit
2344
	 *   element is not a compilation unit, or an element inside a compilation unit
2345
	 * @return the Java element corresponding to the handle identifier
2345
	 * @return the Java element corresponding to the handle identifier
2346
	 * @since 3.0
2346
	 * @since 3.0
2347
	 */
2347
	 */
Lines 2349-2354 Link Here
2349
		if (handleIdentifier == null) {
2349
		if (handleIdentifier == null) {
2350
			return null;
2350
			return null;
2351
		}
2351
		}
2352
		if (owner == null)
2353
			owner = DefaultWorkingCopyOwner.PRIMARY;
2352
		MementoTokenizer memento = new MementoTokenizer(handleIdentifier);
2354
		MementoTokenizer memento = new MementoTokenizer(handleIdentifier);
2353
		JavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
2355
		JavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
2354
		return model.getHandleFromMemento(memento, owner);
2356
		return model.getHandleFromMemento(memento, owner);
(-)src/org/eclipse/jdt/core/tests/model/MementoTests.java (-1 / +12 lines)
Lines 267-273 Link Here
267
/**
267
/**
268
 * Tests that a compilation unit can be persisted and restored using its memento.
268
 * Tests that a compilation unit can be persisted and restored using its memento.
269
 */
269
 */
270
public void testCompilationUnitMemento() {
270
public void testCompilationUnitMemento1() {
271
	ICompilationUnit cu = getCompilationUnit("/P/src/p/X.java");
271
	ICompilationUnit cu = getCompilationUnit("/P/src/p/X.java");
272
	assertMemento(
272
	assertMemento(
273
		"=P/src<p{X.java",
273
		"=P/src<p{X.java",
Lines 278-283 Link Here
278
		"=P/src<{Y.java",
278
		"=P/src<{Y.java",
279
		cu);
279
		cu);
280
}
280
}
281
/*
282
 * Ensure that restoring a compilation unit memento with a null owner doesn't create an
283
 * invalid handle
284
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=205917 )
285
 */
286
public void testCompilationUnitMemento2() throws Exception {
287
	ICompilationUnit cu = getCompilationUnit("/P/src/p/X.java");
288
	String handleIdentifier = cu.getHandleIdentifier();
289
	cu = (ICompilationUnit) JavaCore.create(handleIdentifier, null);
290
	assertEquals(cu, cu); // should not throw an NPE
291
}
281
/**
292
/**
282
 * Tests that a binary field in an external jar can be persisted and restored using its memento.
293
 * Tests that a binary field in an external jar can be persisted and restored using its memento.
283
 */
294
 */

Return to bug 205917