Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceException when ' Save As...' on text file in workspace #182

Closed
ghentschke opened this issue Aug 17, 2023 · 0 comments · Fixed by #183
Closed

ResourceException when ' Save As...' on text file in workspace #182

ghentschke opened this issue Aug 17, 2023 · 0 comments · Fixed by #183
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ghentschke
Copy link
Contributor

ghentschke commented Aug 17, 2023

A ResourceException exception will be thrown when a Save As... will be performed on a opened text file wihin the workspace:

!ENTRY org.eclipse.cdt.lsp 4 0 2023-08-17 13:51:54.974
!MESSAGE Resource '/Cmk1/.clangdNew' does not exist.
!STACK 1
org.eclipse.core.internal.resources.ResourceException(/Cmk1/.clangdNew)[368]: java.lang.Exception: Resource '/Cmk1/.clangdNew' does not exist.
	at org.eclipse.core.internal.resources.ResourceException.provideStackTrace(ResourceException.java:42)
	at org.eclipse.core.internal.resources.ResourceException.<init>(ResourceException.java:38)
	at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:330)
	at org.eclipse.core.internal.resources.Resource.checkAccessible(Resource.java:204)
	at org.eclipse.core.internal.resources.File.getContentDescription(File.java:255)
	at org.eclipse.core.internal.filebuffers.ResourceTextFileBuffer.getContentType(ResourceTextFileBuffer.java:201)
	at org.eclipse.cdt.lsp.ui.navigator.CSymbolsContentProvider$1.dirtyStateChanged(CSymbolsContentProvider.java:72)

It's caused by a IFileBuffer.getContentType() call in org.eclipse.cdt.lsp.ui.navigator.CSymbolsContentProvider.fileBufferListener.new FileBufferListenerAdapter() {...}.dirtyStateChanged(IFileBuffer, boolean)

It seems to be that dirtyStateChanged gets called before the file creation has been finished. May be it should be fixed in org.eclipse.core.internal.filebuffers.ResourceTextFileBuffer.getContentType() as well:

@Override
public IContentType getContentType() throws CoreException {
try {
	if (isDirty()) {
		try(Reader reader = new DocumentReader(getDocument())) {
			IContentDescription desc= Platform.getContentTypeManager().getDescriptionFor(reader, fFile.getName(), NO_PROPERTIES);
			if (desc != null && desc.getContentType() != null)
				return desc.getContentType();
		}
	}
	IContentDescription desc= fFile.getContentDescription();
	if (desc != null && desc.getContentType() != null)
		return desc.getContentType();
	return null;
} catch (IOException x) {
	throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, NLSUtility.format(FileBuffersMessages.FileBuffer_error_queryContentDescription, fFile.getFullPath().toOSString()), x));
}
}

The exception will be triggered in the call fFile.getContentDescription();
A check fFile.exists() prior to the call would fix it.

Steps to reproduce

Start Eclipse IDE with cdt and cdt-lsp plugin runnning. Then:

  1. Open a text file (i.e. .clangd) form workspace project in the editor.
  2. Set focus on that editor tab
  3. Select File -> Save As..
  4. Save file with new name in other workspace project
  5. See the stack trace as above in the log
@ghentschke ghentschke added the bug Something isn't working label Aug 17, 2023
@ghentschke ghentschke self-assigned this Aug 17, 2023
ghentschke added a commit to ghentschke/eclipse-cdt-lsp that referenced this issue Aug 17, 2023
…e in workspace

IFileBuffer.getContentType() throws an exception when the underlying
resource does not exists.

fixes eclipse-cdt#182
ghentschke added a commit to ghentschke/eclipse-cdt-lsp that referenced this issue Aug 18, 2023
…e in workspace

IFileBuffer.getContentType() throws an exception when the underlying
resource does not exists.

fixes eclipse-cdt#182
ghentschke added a commit that referenced this issue Aug 18, 2023
IFileBuffer.getContentType() throws an exception when the underlying
resource does not exists.

fixes #182
@jonahgraham jonahgraham added this to the 1.0.0 milestone Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants