Bug 427552

Summary: KMainWindow::canBeRestored(1) inappropriately returns true when there is no session restore data
Product: [Frameworks and Libraries] frameworks-kxmlgui Reporter: Nate Graham <nate>
Component: generalAssignee: kdelibs bugs <kdelibs-bugs>
Status: REPORTED ---    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Nate Graham 2020-10-11 19:09:35 UTC
Consider the following code:

KConfigGui::setSessionConfig(QStringLiteral("myApp"), QStringLiteral("myApp"));
if (KMainWindow::canBeRestored(1)) {
    // do a bunch of stuff
}


KMainWindow::canBeRestored(1) will return true even though the newly-created session config is empty. This is because internally, it's doing this:

const int n = group.readEntry("NumberOfWindows", 1);
return number >= 1 && number <= n;


So NumberOfWindows is not set, which causes it to fall back to 1. And then the function returns true because the number 1 satisfies both criteria.

This can be trivially fixed by changing the default value of the readEntry() call from 1 to 0, and that's what I did in https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/. However this so breaks Dolphin's manual session restore feature (which accidentally takes advantage of this bug to function) and I had to revert it.

This bug report tracks this issue so that the fix can be merged after Dolphin and potentially other apps are fixed, or KF6--whichever comes first.