diff options
author | Tor Norbye <tnorbye@google.com> | 2012-08-31 08:50:46 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-08-31 08:50:46 -0700 |
commit | ca6ebe92816189f5387a4e1e73571dd959f0c708 (patch) | |
tree | add8ba9fc8f73ca032fdb1ef20f76f262d6c3bbb | |
parent | ec0dfbb255330df32eaafb5d785af458ef9a660c (diff) | |
download | sdk-ca6ebe92816189f5387a4e1e73571dd959f0c708.zip sdk-ca6ebe92816189f5387a4e1e73571dd959f0c708.tar.gz sdk-ca6ebe92816189f5387a4e1e73571dd959f0c708.tar.bz2 |
Avoid "Marker id: 123456789 not found" errors
We have some code which runs asynchronously to add or clean up
error markers. In some cases this code runs after a project has
been closed or deleted, which results in errors. Guard these
marker access points with an IResource.isAccessible() check
(which performs both exists(), and for projects, isOpen()).
Change-Id: Ie4884db13b1e00236c1c219d95c3544fcdee9610
2 files changed, 18 insertions, 5 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseClasspathContainerInitializer.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseClasspathContainerInitializer.java index 403b17b..ebcf9e3 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseClasspathContainerInitializer.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseClasspathContainerInitializer.java @@ -81,7 +81,7 @@ abstract class BaseClasspathContainerInitializer extends ClasspathContainerIniti } else { // no error, remove existing markers. try { - if (project.exists()) { + if (project.isAccessible()) { project.deleteMarkers(markerType, true, IResource.DEPTH_INFINITE); } @@ -92,8 +92,10 @@ abstract class BaseClasspathContainerInitializer extends ClasspathContainerIniti @Override protected IStatus run(IProgressMonitor monitor) { try { - project.deleteMarkers(markerType, true, - IResource.DEPTH_INFINITE); + if (project.isAccessible()) { + project.deleteMarkers(markerType, true, + IResource.DEPTH_INFINITE); + } } catch (CoreException e2) { return e2.getStatus(); } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseProjectHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseProjectHelper.java index d51530c..a7db983 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseProjectHelper.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/BaseProjectHelper.java @@ -131,8 +131,13 @@ public final class BaseProjectHelper { * @param severity the severity of the marker. * @return the IMarker that was added or null if it failed to add one. */ + @Nullable public final static IMarker markResource(IResource resource, String markerId, String message, int lineNumber, int startOffset, int endOffset, int severity) { + if (!resource.isAccessible()) { + return null; + } + try { IMarker marker = resource.createMarker(markerId); marker.setAttribute(IMarker.MESSAGE, message); @@ -176,6 +181,7 @@ public final class BaseProjectHelper { * @param severity the severity of the marker. * @return the IMarker that was added or null if it failed to add one. */ + @Nullable public final static IMarker markResource(IResource resource, String markerId, String message, int severity) { return markResource(resource, markerId, message, -1, severity); @@ -185,16 +191,21 @@ public final class BaseProjectHelper { * Adds a marker to an {@link IProject}. This method does not catch {@link CoreException}, like * {@link #markResource(IResource, String, String, int)}. * - * @param resource the file to be marked + * @param project the project to be marked * @param markerId The id of the marker to add. * @param message the message associated with the mark * @param severity the severity of the marker. * @param priority the priority of the marker * @return the IMarker that was added. - * @throws CoreException + * @throws CoreException if the marker cannot be added */ + @Nullable public final static IMarker markProject(IProject project, String markerId, String message, int severity, int priority) throws CoreException { + if (!project.isAccessible()) { + return null; + } + IMarker marker = project.createMarker(markerId); marker.setAttribute(IMarker.MESSAGE, message); marker.setAttribute(IMarker.SEVERITY, severity); |