acquireInstanceLock() — extract exit/dialog seam to enable unit testing
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
Start in App.java around acquireInstanceLock() (the issue points to lines 312–314) and trace how the lock and already-running branch are handled. Add unit tests for acquiring, detecting and releasing the lock, including the injectable callback. Done means those lifecycle cases pass and GUI startup behavior remains unchanged.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Background
App.acquireInstanceLock() uses NIO FileLock to prevent multiple GUI instances from running simultaneously. When a second instance is detected, it calls System.exit(0) inside a SwingUtilities.invokeLater lambda:
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(...);
System.exit(0); // ← terminates the test JVM if called during tests
});
This is correct production behavior, but it creates a test hazard: any future test that exercises the GUI startup path and encounters an already-held lock will terminate the entire Maven Surefire JVM rather than failing the individual test cleanly.
Problem
System.exitin test JVM — if a test triggers the "already running" branch, the whole test suite crashes with a cryptic Surefire failure instead of a clean test failure.- No coverage of the lock lifecycle — there are no tests verifying: first call acquires lock →
true; second call finds it held →false; lock releases on channel close; next startup succeeds.
Proposed fix
Extract the exit and dialog side-effects behind an injectable strategy (e.g. aRunnableorBiConsumerparameter defaulting to the realSystem.exit+JOptionPanecall). This makesacquireInstanceLock()unit-testable by passing a no-op or capture lambda in tests.
// Example seam
static boolean acquireInstanceLock(Runnable onAlreadyRunning) { ... }
// Production call (unchanged behavior)
acquireInstanceLock(() -> {
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(...);
System.exit(0);
});
});
Acceptance criteria
acquireInstanceLock()does not callSystem.exitdirectly — exit/dialog behavior is injectable- Unit test: first call acquires lock, returns
true - Unit test: second call with lock held returns
falseand invokes theonAlreadyRunningcallback - Unit test: releasing the channel allows a subsequent call to succeed
- Existing GUI startup behavior unchanged
References
- Flagged in PR code review (Copilot, medium severity) on icon-base branch, App.java lines 312–314
- Lingua principale
- Java
- Stelle
- 6
- Fork
- 6
- Merge medio
- 10h 11m
- PR unite (30g)
- 12
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JDiskMark/jdm-java
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement linux
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
documentation linux
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Publish JDiskMark on FlathubApertaenhancement linux
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
bug linux
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di JDiskMark/jdm-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
bloxbean/yaci-store#1445 ·
I maintainer di solito rispondono entro 1 giorno
-
图片灯箱过长的话底部carousel滑动没有惯性Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
-
Spare PermissionAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
Etar-Group/Etar-Calendar#2234 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] MCP resources-as-tools drops invocation context when listing templatesForse già presa @CryoThrust l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
langchain4j/langchain4j#7320 ·
I maintainer di solito rispondono entro 1 giorno