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

(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-6 / +5 lines)
Lines 34-40 Link Here
34
import org.eclipse.core.resources.IWorkspaceRoot;
34
import org.eclipse.core.resources.IWorkspaceRoot;
35
import org.eclipse.core.resources.ProjectScope;
35
import org.eclipse.core.resources.ProjectScope;
36
import org.eclipse.core.resources.ResourcesPlugin;
36
import org.eclipse.core.resources.ResourcesPlugin;
37
import org.eclipse.core.runtime.AssertionFailedException;
38
import org.eclipse.core.runtime.CoreException;
37
import org.eclipse.core.runtime.CoreException;
39
import org.eclipse.core.runtime.IPath;
38
import org.eclipse.core.runtime.IPath;
40
import org.eclipse.core.runtime.IProgressMonitor;
39
import org.eclipse.core.runtime.IProgressMonitor;
Lines 844-850 Link Here
844
	/*
843
	/*
845
	 * Reads and decode an XML classpath string
844
	 * Reads and decode an XML classpath string
846
	 */
845
	 */
847
	public IClasspathEntry[] decodeClasspath(String xmlClasspath, Map unknownElements) throws IOException, AssertionFailedException {
846
	public IClasspathEntry[] decodeClasspath(String xmlClasspath, Map unknownElements) throws IOException, ClasspathEntry.AssertionFailedException {
848
847
849
		ArrayList paths = new ArrayList();
848
		ArrayList paths = new ArrayList();
850
		IClasspathEntry defaultOutput = null;
849
		IClasspathEntry defaultOutput = null;
Lines 2357-2363 Link Here
2357
	 * As a side effect, unknown elements are stored in the given map (if not null)
2356
	 * As a side effect, unknown elements are stored in the given map (if not null)
2358
	 * Throws exceptions if the file cannot be accessed or is malformed.
2357
	 * Throws exceptions if the file cannot be accessed or is malformed.
2359
	 */
2358
	 */
2360
	public IClasspathEntry[] readFileEntriesWithException(Map unknownElements) throws CoreException, IOException, AssertionFailedException {
2359
	public IClasspathEntry[] readFileEntriesWithException(Map unknownElements) throws CoreException, IOException, ClasspathEntry.AssertionFailedException {
2361
		String xmlClasspath;
2360
		String xmlClasspath;
2362
		IFile rscFile = this.project.getFile(JavaProject.CLASSPATH_FILENAME);
2361
		IFile rscFile = this.project.getFile(JavaProject.CLASSPATH_FILENAME);
2363
		if (rscFile.exists()) {
2362
		if (rscFile.exists()) {
Lines 2412-2418 Link Here
2412
		} catch (IOException e) {
2411
		} catch (IOException e) {
2413
			Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$
2412
			Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$
2414
			return JavaProject.INVALID_CLASSPATH;
2413
			return JavaProject.INVALID_CLASSPATH;
2415
		} catch (AssertionFailedException e) {
2414
		} catch (ClasspathEntry.AssertionFailedException e) {
2416
			Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$
2415
			Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$
2417
			return JavaProject.INVALID_CLASSPATH;
2416
			return JavaProject.INVALID_CLASSPATH;
2418
		}
2417
		}
Lines 2500-2506 Link Here
2500
					IClasspathEntry resolvedEntry = null;
2499
					IClasspathEntry resolvedEntry = null;
2501
					try {
2500
					try {
2502
						resolvedEntry = JavaCore.getResolvedClasspathEntry(rawEntry);
2501
						resolvedEntry = JavaCore.getResolvedClasspathEntry(rawEntry);
2503
					} catch (AssertionFailedException e) {
2502
					} catch (ClasspathEntry.AssertionFailedException e) {
2504
						// Catch the assertion failure
2503
						// Catch the assertion failure
2505
						// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992
2504
						// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992
2506
						break;
2505
						break;
Lines 2585-2591 Link Here
2585
						IClasspathEntry resolvedEntry = null;
2584
						IClasspathEntry resolvedEntry = null;
2586
						try {
2585
						try {
2587
							resolvedEntry = manager.getResolvedClasspathEntry(rawEntry, usePreviousSession);
2586
							resolvedEntry = manager.getResolvedClasspathEntry(rawEntry, usePreviousSession);
2588
						} catch (AssertionFailedException e) {
2587
						} catch (ClasspathEntry.AssertionFailedException e) {
2589
							// Catch the assertion failure and set status instead
2588
							// Catch the assertion failure and set status instead
2590
							// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992
2589
							// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992
2591
							unresolvedEntryStatus = new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, e.getMessage());
2590
							unresolvedEntryStatus = new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, e.getMessage());
(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-1 / +9 lines)
Lines 24-30 Link Here
24
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.IWorkspaceRoot;
25
import org.eclipse.core.resources.IWorkspaceRoot;
26
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.resources.ResourcesPlugin;
27
import org.eclipse.core.runtime.AssertionFailedException;
28
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.IPath;
30
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.IStatus;
Lines 58-63 Link Here
58
 * @see IClasspathEntry
57
 * @see IClasspathEntry
59
 */
58
 */
60
public class ClasspathEntry implements IClasspathEntry {
59
public class ClasspathEntry implements IClasspathEntry {
60
	
61
	public static class AssertionFailedException extends RuntimeException {
62
		
63
		private static final long serialVersionUID = -171699380721189572L;
64
65
		public AssertionFailedException(String message) {
66
			super(message);
67
		}
68
	}
61
69
62
	public static final String TAG_CLASSPATH = "classpath"; //$NON-NLS-1$
70
	public static final String TAG_CLASSPATH = "classpath"; //$NON-NLS-1$
63
	public static final String TAG_CLASSPATHENTRY = "classpathentry"; //$NON-NLS-1$
71
	public static final String TAG_CLASSPATHENTRY = "classpathentry"; //$NON-NLS-1$
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-1 / +1 lines)
Lines 1134-1140 Link Here
1134
						new JavaModelStatus(
1134
						new JavaModelStatus(
1135
							IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT,
1135
							IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT,
1136
							Messages.bind(Messages.classpath_cannotReadClasspathFile, javaProject.getElementName()));
1136
							Messages.bind(Messages.classpath_cannotReadClasspathFile, javaProject.getElementName()));
1137
			} catch (AssertionFailedException e) {
1137
			} catch (ClasspathEntry.AssertionFailedException e) {
1138
				classpath = JavaProject.INVALID_CLASSPATH;
1138
				classpath = JavaProject.INVALID_CLASSPATH;
1139
				status =
1139
				status =
1140
					new JavaModelStatus(
1140
					new JavaModelStatus(
(-)model/org/eclipse/jdt/internal/core/CopyPackageFragmentRootOperation.java (-3 / +2 lines)
Lines 11-17 Link Here
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import org.eclipse.core.resources.*;
13
import org.eclipse.core.resources.*;
14
import org.eclipse.core.runtime.AssertionFailedException;
15
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.jdt.core.*;
16
import org.eclipse.jdt.core.*;
Lines 188-194 Link Here
188
			case IClasspathEntry.CPE_LIBRARY:
187
			case IClasspathEntry.CPE_LIBRARY:
189
				try {
188
				try {
190
					return JavaCore.newLibraryEntry(this.destination, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
189
					return JavaCore.newLibraryEntry(this.destination, entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
191
				} catch (AssertionFailedException e) {
190
				} catch (ClasspathEntry.AssertionFailedException e) {
192
					IJavaModelStatus status = new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, e.getMessage());
191
					IJavaModelStatus status = new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, e.getMessage());
193
					throw new JavaModelException(status);
192
					throw new JavaModelException(status);
194
				}
193
				}
Lines 199-205 Link Here
199
			case IClasspathEntry.CPE_VARIABLE:
198
			case IClasspathEntry.CPE_VARIABLE:
200
				try {
199
				try {
201
					return JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
200
					return JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), entry.getExtraAttributes(), entry.isExported());
202
				} catch (AssertionFailedException e) {
201
				} catch (ClasspathEntry.AssertionFailedException e) {
203
					IJavaModelStatus status = new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, e.getMessage());
202
					IJavaModelStatus status = new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, e.getMessage());
204
					throw new JavaModelException(status);
203
					throw new JavaModelException(status);
205
				}
204
				}
(-)model/org/eclipse/jdt/core/JavaCore.java (-21 / +16 lines)
Lines 103-109 Link Here
103
import org.eclipse.core.resources.IWorkspaceRoot;
103
import org.eclipse.core.resources.IWorkspaceRoot;
104
import org.eclipse.core.resources.IWorkspaceRunnable;
104
import org.eclipse.core.resources.IWorkspaceRunnable;
105
import org.eclipse.core.resources.ResourcesPlugin;
105
import org.eclipse.core.resources.ResourcesPlugin;
106
import org.eclipse.core.runtime.Assert;
107
import org.eclipse.core.runtime.CoreException;
106
import org.eclipse.core.runtime.CoreException;
108
import org.eclipse.core.runtime.IConfigurationElement;
107
import org.eclipse.core.runtime.IConfigurationElement;
109
import org.eclipse.core.runtime.IExtension;
108
import org.eclipse.core.runtime.IExtension;
Lines 3765-3775 Link Here
3765
			boolean isExported) {
3764
			boolean isExported) {
3766
3765
3767
		if (containerPath == null) {
3766
		if (containerPath == null) {
3768
			Assert.isTrue(false, "Container path cannot be null"); //$NON-NLS-1$
3767
			throw new ClasspathEntry.AssertionFailedException("Container path cannot be null"); //$NON-NLS-1$
3769
		} else if (containerPath.segmentCount() < 1) {
3768
		} else if (containerPath.segmentCount() < 1) {
3770
			Assert.isTrue(
3769
			throw new ClasspathEntry.AssertionFailedException("Illegal classpath container path: \'" + containerPath.makeRelative().toString() + "\', must have at least one segment (containerID+hints)"); //$NON-NLS-1$//$NON-NLS-2$
3771
				false,
3772
				"Illegal classpath container path: \'" + containerPath.makeRelative().toString() + "\', must have at least one segment (containerID+hints)"); //$NON-NLS-1$//$NON-NLS-2$
3773
		}
3770
		}
3774
		return new ClasspathEntry(
3771
		return new ClasspathEntry(
3775
			IPackageFragmentRoot.K_SOURCE,
3772
			IPackageFragmentRoot.K_SOURCE,
Lines 3952-3964 Link Here
3952
			IClasspathAttribute[] extraAttributes,
3949
			IClasspathAttribute[] extraAttributes,
3953
			boolean isExported) {
3950
			boolean isExported) {
3954
3951
3955
		if (path == null) Assert.isTrue(false, "Library path cannot be null"); //$NON-NLS-1$
3952
		if (path == null) throw new ClasspathEntry.AssertionFailedException("Library path cannot be null"); //$NON-NLS-1$
3956
		if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute: " + path); //$NON-NLS-1$
3953
		if (!path.isAbsolute()) throw new ClasspathEntry.AssertionFailedException("Path for IClasspathEntry must be absolute: " + path); //$NON-NLS-1$
3957
		if (sourceAttachmentPath != null) {
3954
		if (sourceAttachmentPath != null) {
3958
			if (sourceAttachmentPath.isEmpty()) {
3955
			if (sourceAttachmentPath.isEmpty()) {
3959
				sourceAttachmentPath = null; // treat empty path as none
3956
				sourceAttachmentPath = null; // treat empty path as none
3960
			} else if (!sourceAttachmentPath.isAbsolute()) {
3957
			} else if (!sourceAttachmentPath.isAbsolute()) {
3961
				Assert.isTrue(false, "Source attachment path '" //$NON-NLS-1$
3958
				throw new ClasspathEntry.AssertionFailedException("Source attachment path '" //$NON-NLS-1$
3962
						+ sourceAttachmentPath
3959
						+ sourceAttachmentPath
3963
						+ "' for IClasspathEntry must be absolute"); //$NON-NLS-1$
3960
						+ "' for IClasspathEntry must be absolute"); //$NON-NLS-1$
3964
			}
3961
			}
Lines 4007-4013 Link Here
4007
	 */
4004
	 */
4008
	public static IClasspathEntry newProjectEntry(IPath path, boolean isExported) {
4005
	public static IClasspathEntry newProjectEntry(IPath path, boolean isExported) {
4009
4006
4010
		if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
4007
		if (!path.isAbsolute()) throw new ClasspathEntry.AssertionFailedException("Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
4011
4008
4012
		return newProjectEntry(
4009
		return newProjectEntry(
4013
			path,
4010
			path,
Lines 4072-4078 Link Here
4072
			IClasspathAttribute[] extraAttributes,
4069
			IClasspathAttribute[] extraAttributes,
4073
			boolean isExported) {
4070
			boolean isExported) {
4074
4071
4075
		if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
4072
		if (!path.isAbsolute()) throw new ClasspathEntry.AssertionFailedException("Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
4076
4073
4077
		return new ClasspathEntry(
4074
		return new ClasspathEntry(
4078
			IPackageFragmentRoot.K_SOURCE,
4075
			IPackageFragmentRoot.K_SOURCE,
Lines 4274-4283 Link Here
4274
	 */
4271
	 */
4275
	public static IClasspathEntry newSourceEntry(IPath path, IPath[] inclusionPatterns, IPath[] exclusionPatterns, IPath specificOutputLocation, IClasspathAttribute[] extraAttributes) {
4272
	public static IClasspathEntry newSourceEntry(IPath path, IPath[] inclusionPatterns, IPath[] exclusionPatterns, IPath specificOutputLocation, IClasspathAttribute[] extraAttributes) {
4276
4273
4277
		if (path == null) Assert.isTrue(false, "Source path cannot be null"); //$NON-NLS-1$
4274
		if (path == null) throw new ClasspathEntry.AssertionFailedException("Source path cannot be null"); //$NON-NLS-1$
4278
		if (!path.isAbsolute()) Assert.isTrue(false, "Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
4275
		if (!path.isAbsolute()) throw new ClasspathEntry.AssertionFailedException("Path for IClasspathEntry must be absolute"); //$NON-NLS-1$
4279
		if (exclusionPatterns == null) Assert.isTrue(false, "Exclusion pattern set cannot be null"); //$NON-NLS-1$
4276
		if (exclusionPatterns == null) throw new ClasspathEntry.AssertionFailedException("Exclusion pattern set cannot be null"); //$NON-NLS-1$
4280
		if (inclusionPatterns == null) Assert.isTrue(false, "Inclusion pattern set cannot be null"); //$NON-NLS-1$
4277
		if (inclusionPatterns == null) throw new ClasspathEntry.AssertionFailedException("Inclusion pattern set cannot be null"); //$NON-NLS-1$
4281
4278
4282
		return new ClasspathEntry(
4279
		return new ClasspathEntry(
4283
			IPackageFragmentRoot.K_SOURCE,
4280
			IPackageFragmentRoot.K_SOURCE,
Lines 4418-4428 Link Here
4418
			IClasspathAttribute[] extraAttributes,
4415
			IClasspathAttribute[] extraAttributes,
4419
			boolean isExported) {
4416
			boolean isExported) {
4420
4417
4421
		if (variablePath == null) Assert.isTrue(false, "Variable path cannot be null"); //$NON-NLS-1$
4418
		if (variablePath == null) throw new ClasspathEntry.AssertionFailedException("Variable path cannot be null"); //$NON-NLS-1$
4422
		if (variablePath.segmentCount() < 1) {
4419
		if (variablePath.segmentCount() < 1) {
4423
			Assert.isTrue(
4420
			throw new ClasspathEntry.AssertionFailedException("Illegal classpath variable path: \'" + variablePath.makeRelative().toString() + "\', must have at least one segment"); //$NON-NLS-1$//$NON-NLS-2$
4424
				false,
4425
				"Illegal classpath variable path: \'" + variablePath.makeRelative().toString() + "\', must have at least one segment"); //$NON-NLS-1$//$NON-NLS-2$
4426
		}
4421
		}
4427
4422
4428
		return new ClasspathEntry(
4423
		return new ClasspathEntry(
Lines 4641-4647 Link Here
4641
	 */
4636
	 */
4642
	public static void setClasspathContainer(IPath containerPath, IJavaProject[] affectedProjects, IClasspathContainer[] respectiveContainers, IProgressMonitor monitor) throws JavaModelException {
4637
	public static void setClasspathContainer(IPath containerPath, IJavaProject[] affectedProjects, IClasspathContainer[] respectiveContainers, IProgressMonitor monitor) throws JavaModelException {
4643
		if (affectedProjects.length != respectiveContainers.length)
4638
		if (affectedProjects.length != respectiveContainers.length)
4644
			Assert.isTrue(false, "Projects and containers collections should have the same size"); //$NON-NLS-1$
4639
			throw new ClasspathEntry.AssertionFailedException("Projects and containers collections should have the same size"); //$NON-NLS-1$
4645
		SetContainerOperation operation = new SetContainerOperation(containerPath, affectedProjects, respectiveContainers);
4640
		SetContainerOperation operation = new SetContainerOperation(containerPath, affectedProjects, respectiveContainers);
4646
		operation.runOperation(monitor);
4641
		operation.runOperation(monitor);
4647
	}
4642
	}
Lines 4692-4698 Link Here
4692
		IProgressMonitor monitor)
4687
		IProgressMonitor monitor)
4693
		throws JavaModelException {
4688
		throws JavaModelException {
4694
4689
4695
		if (path == null) Assert.isTrue(false, "Variable path cannot be null"); //$NON-NLS-1$
4690
		if (path == null) throw new ClasspathEntry.AssertionFailedException("Variable path cannot be null"); //$NON-NLS-1$
4696
		setClasspathVariables(new String[]{variableName}, new IPath[]{ path }, monitor);
4691
		setClasspathVariables(new String[]{variableName}, new IPath[]{ path }, monitor);
4697
	}
4692
	}
4698
4693
Lines 4727-4733 Link Here
4727
		IProgressMonitor monitor)
4722
		IProgressMonitor monitor)
4728
		throws JavaModelException {
4723
		throws JavaModelException {
4729
4724
4730
		if (variableNames.length != paths.length)	Assert.isTrue(false, "Variable names and paths collections should have the same size"); //$NON-NLS-1$
4725
		if (variableNames.length != paths.length)	throw new ClasspathEntry.AssertionFailedException("Variable names and paths collections should have the same size"); //$NON-NLS-1$
4731
		SetVariablesOperation operation = new SetVariablesOperation(variableNames, paths, true/*update preferences*/);
4726
		SetVariablesOperation operation = new SetVariablesOperation(variableNames, paths, true/*update preferences*/);
4732
		operation.runOperation(monitor);
4727
		operation.runOperation(monitor);
4733
	}
4728
	}
(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (-2 / +2 lines)
Lines 4579-4585 Link Here
4579
			ClasspathEntry.NO_EXTRA_ATTRIBUTES);
4579
			ClasspathEntry.NO_EXTRA_ATTRIBUTES);
4580
		IJavaModelStatus status = JavaConventions.validateClasspathEntry(proj, cp, false);
4580
		IJavaModelStatus status = JavaConventions.validateClasspathEntry(proj, cp, false);
4581
		assertEquals(
4581
		assertEquals(
4582
			"assertion failed: Source attachment path \'jclMin.zip\' for IClasspathEntry must be absolute",
4582
			"Source attachment path \'jclMin.zip\' for IClasspathEntry must be absolute",
4583
			status.getMessage());
4583
			status.getMessage());
4584
	} finally {
4584
	} finally {
4585
		this.deleteProject("P");
4585
		this.deleteProject("P");
Lines 4607-4613 Link Here
4607
		);
4607
		);
4608
		assertMarkers(
4608
		assertMarkers(
4609
			"Unexpected markers",
4609
			"Unexpected markers",
4610
			"assertion failed: Source attachment path \'tmp.zip\' for IClasspathEntry must be absolute",
4610
			"Source attachment path \'tmp.zip\' for IClasspathEntry must be absolute",
4611
			javaProject);
4611
			javaProject);
4612
	} finally {
4612
	} finally {
4613
		this.deleteProject("P");
4613
		this.deleteProject("P");

Return to bug 245830