Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ protected void create() {
fDocumentProvider = createDocumentProvider(fEditorInput);
try {
fDocumentProvider.connect(fEditorInput);
// Verify that the document is available after connect()
// This can fail if the file was deleted/moved during editor initialization
// or if there's a race condition with workspace events
IDocument document = fDocumentProvider.getDocument(fEditorInput);
if (document == null) {
throw new CoreException(new org.eclipse.core.runtime.Status(
org.eclipse.core.runtime.IStatus.ERROR,
"org.eclipse.pde.ui", //$NON-NLS-1$
"Document not available after connecting to document provider for input: " + fEditorInput.getName())); //$NON-NLS-1$
Comment on lines +170 to +173
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this substantially improve the situation? To me it seems like we are not trading a NullPointerException for a a CoreException?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore calling the new Status constructor can be replaced by the simpler Status.error() factory:

Suggested change
throw new CoreException(new org.eclipse.core.runtime.Status(
org.eclipse.core.runtime.IStatus.ERROR,
"org.eclipse.pde.ui", //$NON-NLS-1$
"Document not available after connecting to document provider for input: " + fEditorInput.getName())); //$NON-NLS-1$
throw new CoreException(Status.error("Document not available after connecting to document provider for input: " + fEditorInput.getName())); //$NON-NLS-1$

}
fModel = createModel(fEditorInput);
if (fModel instanceof IModelChangeProvider) {
fModelListener = e -> {
Expand Down
Loading