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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/ClassFileTests.java (+33 lines)
Lines 12-17 Link Here
12
12
13
import java.io.IOException;
13
import java.io.IOException;
14
14
15
import org.eclipse.core.resources.IFolder;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IProgressMonitor;
Lines 451-456 Link Here
451
}
452
}
452
453
453
/*
454
/*
455
 * Ensures that if a root folder (that has a jar like name) is opened, and then a Jar package fragment root created on this root folder,
456
 * then attempting to open a class file in this folder doesn't throw a ClassCastException
457
 * (regression test for bug 204652 "Open Type": ClassCastException in conjunction with a class folder)
458
 */
459
public void testJarLikeRootFolder() throws CoreException {
460
	try {
461
		IJavaProject p = createJavaProject("P1", new String[0], new String[] {"/P1/classFolder.jar"}, "");
462
		IFolder folder = createFolder("/P1/classFolder.jar/p");
463
		createFile("/P1/classFolder.jar/X.class", "p");
464
		
465
		// populate cache with a valid package fragment root and a valid package fragment
466
		IPackageFragment validPkg = p.getPackageFragmentRoot(folder.getParent()).getPackageFragment("p");
467
		validPkg.open(null);
468
469
		// create an invalid package fragment root and an invalid package fragment
470
		IPackageFragment invalidPkg = p.getPackageFragmentRoot("/P1/classFolder.jar").getPackageFragment("p");
471
		
472
		// ensure that the class fille cannot be opened with a valid excepption
473
		IClassFile openable = invalidPkg.getClassFile("X.class");
474
		JavaModelException expected = null;
475
		try {
476
			openable.open(null);
477
		} catch (JavaModelException e) {
478
			expected = e;
479
		}
480
		assertExceptionEquals("Unexpected exception", "classFolder.jar [in P1] does not exist", expected);
481
	} finally {
482
		deleteProject("P1");
483
	}
484
}
485
486
/*
454
 * Ensures that the parameter names of a binary method with source attached are correct.
487
 * Ensures that the parameter names of a binary method with source attached are correct.
455
 */
488
 */
456
public void testParameterNames01() throws CoreException {
489
public void testParameterNames01() throws CoreException {
(-)model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java (-4 / +5 lines)
Lines 324-330 Link Here
324
	if (!(o instanceof PackageFragmentRoot))
324
	if (!(o instanceof PackageFragmentRoot))
325
		return false;
325
		return false;
326
	PackageFragmentRoot other = (PackageFragmentRoot) o;
326
	PackageFragmentRoot other = (PackageFragmentRoot) o;
327
	return this.resource.equals(other.resource) && 
327
	return getResource().equals(other.getResource()) && 
328
			this.parent.equals(other.parent);
328
			this.parent.equals(other.parent);
329
}
329
}
330
330
Lines 441-448 Link Here
441
	}
441
	}
442
}		
442
}		
443
public String getElementName() {
443
public String getElementName() {
444
	if (this.resource instanceof IFolder)
444
	IResource res = getResource();
445
		return ((IFolder) this.resource).getName();
445
	if (res instanceof IFolder)
446
		return ((IFolder) res).getName();
446
	return ""; //$NON-NLS-1$
447
	return ""; //$NON-NLS-1$
447
}
448
}
448
/**
449
/**
Lines 703-709 Link Here
703
}
704
}
704
705
705
public int hashCode() {
706
public int hashCode() {
706
	return this.resource.hashCode();
707
	return getResource().hashCode();
707
}
708
}
708
709
709
/**
710
/**
(-)model/org/eclipse/jdt/internal/core/ClassFile.java (-2 / +9 lines)
Lines 18-23 Link Here
18
18
19
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFolder;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.IPath;
Lines 791-798 Link Here
791
	IStatus status = validateClassFile();
792
	IStatus status = validateClassFile();
792
	if (!status.isOK()) 
793
	if (!status.isOK()) 
793
		return status;
794
		return status;
794
	if (underlyingResource != null && !underlyingResource.isAccessible()) 
795
	if (underlyingResource != null) {
795
		return newDoesNotExistStatus();
796
		if (!underlyingResource.isAccessible()) 
797
			return newDoesNotExistStatus();
798
		PackageFragmentRoot root;
799
		if ((underlyingResource instanceof IFolder) && (root = getPackageFragmentRoot()).isArchive()) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=204652
800
			return root.newDoesNotExistStatus();
801
		}
802
	}
796
	return JavaModelStatus.VERIFIED_OK;
803
	return JavaModelStatus.VERIFIED_OK;
797
}
804
}
798
}
805
}

Return to bug 204652