Launch AdminUI helper threads outside the constructor (CodeQL java/thread-start-in-constructor)#239
Open
vharseko wants to merge 2 commits into
Open
Conversation
…read-start-in-constructor) The AdminUI() constructor started two threads - one that builds the Swing frame (joined before the constructor returned) and one that resolves the local host name - so both anonymous Thread subclasses captured `this` and could touch AdminUI fields before construction had finished (a hazard in particular if the class were subclassed). Move that block into a new public launch() method and have main() call it right after constructing the instance, before connect(). AdminUI is only ever created by its own main(), and the collaborator classes merely hold a reference passed to their setup() methods, so no other caller is affected. The main() flow is unchanged: construct (records the RMI host) -> launch (builds the frame, waits for it, starts the host-name lookup) -> connect. The frame is still fully built before connect() runs.
maximthomas
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves both
java/thread-start-in-constructoralerts inAdminUI(lines 234and 247). The
AdminUI()constructor started two threads:JFrame/splash, thensetupFrame()),joined before the constructor returned; and
InetAddress.getLocalHost()), fire-and-forget.Both are anonymous
Threadsubclasses that capturethis, so they could observeAdminUIbefore its construction finished — the exact pattern the rule warnsabout (most dangerous if the class is subclassed and a helper thread calls an
overridden method against uninitialised subclass state).
Change
The thread block is moved verbatim from the constructor into a new
public void launch()method, andmain()calls it right after construction:AdminUIis only ever instantiated by its ownmain()(verified across therepo — the other UI classes just hold a reference handed to their
setup(ui)methods), so moving the launch out of the constructor affects no other caller.
Behaviour
The
main()sequence is unchanged: construct (records the RMI host) →launch()(builds the frame, waits for it, kicks off the host-name lookup) →
connect().The frame is still fully built before
connect()runs, so the RMI connection andwindow title behave exactly as before. The
connect()call previously performedinside the
AdminUI(String)constructor now runs frommain()afterlaunch();refresh()already guards_tabbedPane != null, so the remaining convenienceconstructors stay safe.
Testing
mvn -o -pl persistit/ui compile— BUILD SUCCESS.