#2040: Fix buggy workspace selection - #2309
Conversation
…election-buggy # Conflicts: # gui/src/main/java/com/devonfw/ide/gui/MainController.java
|
I've taken this PR since i encountered this bug while working on #2214. This fix works perfectly fine, I merged the current main-branch into it and tested the fix. I think this counts as a Team Review so I'll move it to In Review. |
Coverage Report for CI Build 31779828913Warning No base build found for commit Coverage: 72.916%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
There was a problem hiding this comment.
Thanks for picking this up and carrying #2095 over the finish line 👍 The diagnosis here is good, and the fix attacks the actual root cause rather than papering over the symptom.
Worth spelling out, because it explains the odd symptom in #2040: the old code re-registered the handler at the end of setWorkspaceComboBox(), so on the second project selection the previous handler was still attached while getItems().clear() / addAll(...) mutated the list. It fired with a stale workspace name, updateContext(...) hit FileNotFoundException in GuiStateManager.switchContext, and errorDialog.showAndWait() then spun up a nested JavaFX event loop in the middle of that mutation - which is almost certainly how you end up with an empty selection field and a duplicated item list. Registering once in initialize() plus the null guard closes exactly that window. Good fix.
No blockers. Everything below is Should-fix or Minor.
Should-fix
1. CHANGELOG.adoc entry is missing
The checkbox is unchecked in the PR description, and I confirmed there is no 2040 entry in CHANGELOG.adoc. #2040 is labelled GUI, not internal, and the bug shipped to users (the reporter hit it on 2026.06.001-...-SNAPSHOT), so per DoD.adoc it belongs in the next open release section. On current main that section is == 2026.08.002 (milestone 49) and it is still empty:
== 2026.08.002
Release with new features and bugfixes:
* https://github.com/devonfw/IDEasy/issues/2040[#2040]: Fixed buggy workspace selection in the GUIWhy: the CHANGELOG is the release-notes source for end users; if it is not written while the change is fresh, nobody reconstructs it at release time.
2. Commit message points at the wrong issue
The single functional commit is:
#1936:fix workspace ComboBox reset on project switch
#1936 is "Improve localization of the GUI" (closed, unrelated). GitHub will auto-link this commit to that issue. Two things per commit.adoc: the issue id must be the one actually addressed, and the format is #<issue-id>: <describe your change> - note the space after the colon.
#2040: fix workspace ComboBox reset on project switch
Why: the #id: prefix is not decoration, it is the mechanism that ties the commit to the issue in GitHub's timeline. A wrong id silently attaches this change to unrelated history.
3. No regression test, although the harness for one already exists
This is the part I would most like to see added. gui/src/test/java/com/devonfw/ide/gui/AppBaseTest.java is already a headless TestFX test of this exact controller, and already covers neighbouring behaviour (testIdeOpenButtonsEnabledWhenWorkspaceSelected, testWorkspaceComboboxEnabledEnabledWhenProjectSelected). Per AGENTS.md a bugfix should start from a test that reproduces the bug, and here that is roughly a dozen lines:
@Test
public void testWorkspaceSelectionIsResetWhenProjectChanges() {
interact(() -> selectedProject.getSelectionModel().select("project-1"));
interact(() -> selectedWorkspace.getSelectionModel().select("main"));
interact(() -> selectedProject.getSelectionModel().select("project-2"));
// no stale selection, no duplicated items, buttons back to disabled
...
}Two caveats so this is not a trap:
FakeProjectFolderStructureHelpercurrently creates only amainworkspace per project, so it needs a second workspace folder to exercise the "workspace other than main" path from the issue.AppBaseTeststatic-importsorg.testfx.assertions.api.Assertions.assertThat; for the item-list assertion you will want AssertJ (doesNotHaveDuplicates()), so qualify it or import it explicitly - AGENTS.md mandates AssertJ for assertions.
Why: without it, the next refactoring of setWorkspaceComboBox() silently reopens exactly this bug, and it is a bug that only manifests on the second project switch - the kind nobody re-checks manually.
4. Verify in the environment where the bug actually reproduces
The reporter was explicit in #2040: "I could not reproduce this behavior when running AppLauncher.main() from my IDE; in this case the selector works absolutely fine." The testing instructions inherited from #2095 say "Open GUI by running AppLauncher", i.e. the one environment where the bug never showed. Green CI does not cover this either.
Please confirm before merge that this was verified via ide gui on a snapshot build (ideally macOS, as reported). If it was already tested that way, just say so in the PR and this is resolved.
5. Branch is behind main
GitHub reports BEHIND. Per DoD.adoc, the feature branch has to be up-to-date with main before merge. Update branch should suffice, mergeable is clean.
6. Issue #2040 has no milestone
Milestones must be set before issues/PRs get closed (DoD.adoc). Also worth closing the loop on #2095 by linking it here as superseded.
Minor
Inline comments cover: the @FXML annotation on onWorkspaceSelected, the duplicated four-button enable/disable blocks (2 sites), and the ordering of setValue(null).
One more, pre-existing and not introduced by you, so purely optional while you are in this method. setWorkspaceComboBox() still has:
} catch (NotDirectoryException e) {
throw new RuntimeException(e);
}Per coding-conventions.adoc, section "Catching and handling Exceptions" the cause is kept (good) but the message is not: throw new IllegalStateException("Failed to read workspaces for project " + selectedProject.getValue(), e) makes the stacktrace self-explaining. Entirely non-blocking.
This PR fixes #2040
Implemented changes:
Testing instructions
Please add conscise, understandable instructions on how a reviewer can test/verify the functionality of your contribution here:
Checklist for this PR
Make sure everything is checked before merging this PR. For further info please also see
our DoD.
mvn clean testlocally all tests pass and build is successful#«issue-id»: «brief summary»(e.g.#921: fixed setup.batand notfeature/921 fixed setup.bat). If no issue ID exists, title only.In Progressand assigned to you or there is no issue (might happen for very small PRs)with
internalpom.xmlfiles or otherwise if runtime dependencies changed, you have updated our LICENSE.asciidoc