From 424073925cd7b115558c284446123230c3c2834e Mon Sep 17 00:00:00 2001 From: teicher Date: Fri, 18 Jun 2004 17:30:18 +0000 Subject: fixes 67437 [implementation] ClassCastException when performing saveAs --- .../internal/filebuffers/ContainerGenerator.java | 20 ++++++++++++++++---- .../filebuffers/FileBuffersMessages.properties | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'org.eclipse.core.filebuffers') diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ContainerGenerator.java b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ContainerGenerator.java index 06b8067197c..f64e0bb8edf 100644 --- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ContainerGenerator.java +++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/ContainerGenerator.java @@ -20,8 +20,10 @@ import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubProgressMonitor; public class ContainerGenerator { @@ -78,9 +80,14 @@ public class ContainerGenerator { // Does the container exist already? IWorkspaceRoot root= fWorkspace.getRoot(); - fContainer= (IContainer) root.findMember(fContainerFullPath); - if (fContainer != null) + IResource found= root.findMember(fContainerFullPath); + if (found instanceof IContainer) { + fContainer= (IContainer) found; return; + } else if (found != null) { + // fContainerFullPath specifies a file as directory + throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getFormattedString("ContainerGenerator.destinationMustBeAContainer", fContainerFullPath), null)); //$NON-NLS-1$ + } // Create the container for the given path fContainer= root; @@ -88,8 +95,13 @@ public class ContainerGenerator { String currentSegment = fContainerFullPath.segment(i); IResource resource = fContainer.findMember(currentSegment); if (resource != null) { - fContainer= (IContainer) resource; - monitor.worked(1000); + if (resource instanceof IContainer) { + fContainer= (IContainer) resource; + monitor.worked(1000); + } else { + // fContainerFullPath specifies a file as directory + throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.getFormattedString("ContainerGenerator.destinationMustBeAContainer", resource.getFullPath()), null)); //$NON-NLS-1$ + } } else { if (i == 0) { diff --git a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.properties b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.properties index 271f2e84f86..efbe8b0d373 100644 --- a/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.properties +++ b/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileBuffersMessages.properties @@ -21,6 +21,7 @@ FileBuffer.status.error= Error FileBufferManager.error.canNotCreateFilebuffer= Cannot create file buffer. ContainerGenerator.task.creatingContainer= Creating container... +ContainerGenerator.destinationMustBeAContainer=Specified path is not a folder: {0} ResourceTextFileBuffer.error.unsupported_encoding.message_arg= Character encoding \"{0}\" is not supported by this platform. ResourceTextFileBuffer.error.closeReader= Could not close reader. -- cgit v1.2.3