diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp
index 94473ab132325ba8ce6002e6b574bbe62bbe29f5..11e397bf4bffcef66017cfd74c0feab64e683cac 100644
--- a/src/plugins/coreplugin/editormanager/editormanager.cpp
+++ b/src/plugins/coreplugin/editormanager/editormanager.cpp
@@ -1282,8 +1282,7 @@ void EditorManager::restoreEditorState(IEditor *editor)
 {
     QTC_ASSERT(editor, return);
     QString fileName = editor->file()->fileName();
-    if (m_d->m_editorStates.contains(fileName))
-        editor->restoreState(m_d->m_editorStates.value(fileName).toByteArray());
+    editor->restoreState(m_d->m_editorStates.value(fileName).toByteArray());
 }
 
 bool EditorManager::saveEditor(IEditor *editor)
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index e4788adfc3f34192ab30fffbe6b866a36ed30e92..9034469a45663cf64dbc28bf0e20aae00083a62c 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -609,8 +609,6 @@ bool BaseTextEditor::open(const QString &fileName)
 {
     if (d->m_document->open(fileName)) {
         moveCursor(QTextCursor::Start);
-        if (d->m_displaySettings.m_autoFoldFirstComment)
-            d->collapseLicenseHeader();
         setReadOnly(d->m_document->hasDecodingError());
         return true;
     }
@@ -1531,8 +1529,6 @@ void BaseTextEditor::memorizeCursorPosition()
 void BaseTextEditor::restoreCursorPosition()
 {
     restoreState(d->m_tempState);
-    if (d->m_displaySettings.m_autoFoldFirstComment)
-        d->collapseLicenseHeader();
 }
 
 QByteArray BaseTextEditor::saveState() const
@@ -1567,6 +1563,11 @@ QByteArray BaseTextEditor::saveState() const
 
 bool BaseTextEditor::restoreState(const QByteArray &state)
 {
+    if (state.isEmpty()) {
+        if (d->m_displaySettings.m_autoFoldFirstComment)
+            d->collapseLicenseHeader();
+        return false;
+    }
     int version;
     int vval;
     int hval;
@@ -1588,6 +1589,9 @@ bool BaseTextEditor::restoreState(const QByteArray &state)
             if (block.isValid())
                 TextBlockUserData::doCollapse(block, false);
         }
+    } else {
+        if (d->m_displaySettings.m_autoFoldFirstComment)
+            d->collapseLicenseHeader();
     }
 
     d->m_lastCursorChangeWasInteresting = false; // avoid adding last position to history