1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 10:45:37 +02:00

Bug 280262 NPE in editors in closed projects => user friendly error message

createProjectDescription throws a CoreException as defined by the API rather than returning null when the project is inaccessible.
This commit is contained in:
James Blackburn 2010-02-24 11:57:19 +00:00
parent e1c516fe2c
commit 25b266f275
4 changed files with 59 additions and 15 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others.
* Copyright (c) 2007, 2010 Intel 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
@ -127,6 +127,28 @@ public class CProjectDescriptionBasicTests extends BaseTestCase{
}
public void testCreateProjectDescriptionInvalidProject() throws Exception {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("someProject");
assertTrue(!project.isAccessible());
ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
boolean exception = false;
try {
mngr.createProjectDescription(null, false, true);
} catch (CoreException e) {
exception = true;
}
assertTrue(exception);
exception = false;
try {
mngr.createProjectDescription(project, false, true);
} catch (CoreException e) {
exception = true;
}
assertTrue(exception);
}
public void testSetInvalidCreatingDescription() throws Exception {
IWorkspace wsp = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = wsp.getRoot();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2008 Intel Corporation and others.
* Copyright (c) 2007, 2010 Intel 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
@ -73,6 +73,7 @@ public interface ICProjectDescriptionManager {
* and returns a writable project description which is either empty or a copy of the previous configuration description
* if loadIfExists == true.
* @see #createProjectDescription(IProject, boolean, boolean)
* @throws CoreException if the Project doesn't exist, or the storage couldn't be found
*/
ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists) throws CoreException;
@ -89,7 +90,7 @@ public interface ICProjectDescriptionManager {
*
* NOTE: changes made to the returned project description will not be applied until the {@link #setProjectDescription(IProject, ICProjectDescription)} is called
* @return {@link ICProjectDescription}
* @throws CoreException
* @throws CoreException if the Project doesn't exist, or the storage couldn't be found
*/
ICProjectDescription createProjectDescription(IProject project, boolean loadIfExists, boolean creating) throws CoreException;

View file

@ -390,19 +390,28 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
}
public ICProjectDescription getProjectDescription(IProject project, int flags) {
AbstractCProjectDescriptionStorage storage = getProjectDescriptionStorage(project);
if (storage != null) {
try {
return storage.getProjectDescription(flags, new NullProgressMonitor());
} catch (CoreException e) {
// FIXME Currently the resource change handler ResourceChangeHandler.getProjectDescription(...)
// Does this when the project is closed. Don't log an error or the tests will fail
try {
return getProjectDescriptionInternal(project, flags);
} catch (CoreException e) {
// FIXME Currently the resource change handler ResourceChangeHandler.getProjectDescription(...)
// Does this when the project is closed. Don't log an error or the tests will fail
// CCorePlugin.log(e);
}
}
return null;
}
/**
* Base method for getting a Project's Description
* @param project
* @param flags
* @return ICProjectDescription
* @throws CoreException if project description isn't available
*/
private ICProjectDescription getProjectDescriptionInternal(IProject project, int flags) throws CoreException {
AbstractCProjectDescriptionStorage storage = getProjectDescriptionStorage(project);
return storage.getProjectDescription(flags, new NullProgressMonitor());
}
/**
* Run the workspace modification in the current thread using the workspace scheduling rule
* Equivalent to: <code>runWspModification(IWorkspaceRunnable, ResourcecPlugin.getWorkspace().getRoot(), IProgressMonitor)</code>
@ -587,7 +596,7 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
flags |= loadIfExists ? 0 : ICProjectDescriptionManager.GET_EMPTY_PROJECT_DESCRIPTION;
flags |= creating ? ICProjectDescriptionManager.PROJECT_CREATING : 0;
return getProjectDescription(project, flags);
return getProjectDescriptionInternal(project, flags);
}
public ScannerInfoProviderProxy getScannerInfoProviderProxy(IProject project){
@ -816,8 +825,19 @@ public class CProjectDescriptionManager implements ICProjectDescriptionManager {
return settingProjectDescription.get();
}
private AbstractCProjectDescriptionStorage getProjectDescriptionStorage(IProject project) {
return CProjectDescriptionStorageManager.getInstance().getProjectDescriptionStorage(project);
/**
* Base for getting a project desc's storage. project must be accessible.
* @param project
* @return ProjectDescription storage
* @throws CoreException if Project isn't accessible
*/
private AbstractCProjectDescriptionStorage getProjectDescriptionStorage(IProject project) throws CoreException {
if (project == null || !project.isAccessible())
throw ExceptionFactory.createCoreException(MessageFormat.format(CCorePlugin.getResourceString("ProjectDescription.ProjectNotAccessible"), new Object[] {project != null ? project.getName() : "<null>"})); //$NON-NLS-1$ //$NON-NLS-2$
AbstractCProjectDescriptionStorage storage = CProjectDescriptionStorageManager.getInstance().getProjectDescriptionStorage(project);
if (storage == null)
throw ExceptionFactory.createCoreException(SettingsModelMessages.getString("CProjectDescriptionManager.FailedToGetStorage") + project.getName()); //$NON-NLS-1$
return storage;
}
/**

View file

@ -31,13 +31,14 @@ CProjectDescriptionManager.9=invalid project file format
CProjectDescriptionManager.0=Initiating resource change handling..
CProjectDescriptionManager.10=invalid project file format
CProjectDescriptionManager.11=storage file not found
CProjectDescriptionManager.12=Serialing CDT Project settings..
CProjectDescriptionManager.12=Serializing CDT Project settings..
CProjectDescriptionManager.13=Refreshing the project settings
CProjectDescriptionManager.14=workspace info element does not exist
CProjectDescriptionManager.15=Preference Configuration
CProjectDescriptionManager.16=attempt to set description for the non-openned project
CProjectDescriptionManager.17=unable to apply the invalid project description for project
CProjectDescriptionManager.cfgIDAlreadyExists=Configuration with ID: {0} already exists in passed in settings storage
CProjectDescriptionManager.FailedToGetStorage=Failed to get storage for project:
CProjectDescriptionManager.illegalDeltaKind=Illegal delta kind
CProjectDescriptionManager.wrongTypeOfResourceDescription=Wrong type of resource description:
CFolderDescription.0=data was not created