Fix disconnect notifiers
Build and Test j3270 / Build JAR & Run Tests (Java 11) (push) Successful in 53s
Build and Test j3270 / Build JAR & Run Tests (Java 21) (push) Successful in 1m30s
Build and Test j3270 / Build JAR & Run Tests (Java 17) (push) Successful in 1m37s

This commit is contained in:
2026-09-28 13:01:03 +00:00
parent daac11472d
commit fac6ac8bfb
5 changed files with 70 additions and 3 deletions
@@ -945,8 +945,14 @@ public class J3270App extends JFrame implements ConnectionListener, ScreenUpdate
}
public boolean isConnected() {
return client != null && (client.isConnected() ||
(client.getConnectionState() != null && client.getConnectionState().isConnected()));
if (client == null) {
return false;
}
ConnectionState state = client.getConnectionState();
if (state == null || state == ConnectionState.NOT_CONNECTED) {
return false;
}
return client.isConnected() || state.isConnected();
}
public String getConnectedTarget() {
@@ -1213,6 +1219,7 @@ public class J3270App extends JFrame implements ConnectionListener, ScreenUpdate
setTitle("j3270 — " + lastHost + ":" + lastPort + " [Reconnecting...]");
} else if (newState == ConnectionState.NOT_CONNECTED) {
setTitle("j3270 — Java TN3270 Terminal Emulator");
syncModeMenuItems();
} else if (newState.isFullSession() && !oldState.isFullSession()) {
String tlsIndicator = (client != null && client.getConfig().isUseTls()) ?
(client.getConfig().isTlsVerifyCert() ? " [TLS]" : " [TLS/Unverified]") : "";
@@ -294,4 +294,35 @@ public class ConnectionConflictTest {
assertEquals(haus.nightmare.lib3270j.ConnectionState.NOT_CONNECTED, client.getConnectionState());
assertFalse(client.isConnected());
}
@Test
@DisplayName("When not connected, connect does not trigger abort connection dialog for previously closed connection")
public void testNotConnectedDoesNotTriggerAbortDialog() throws Exception {
J3270App app = createApp();
if (app == null) return;
// Simulate a previously closed connection
ConnectionConfig config1 = new ConnectionConfig("host1.test", 23, TerminalModel.IBM_3278_2);
app.connect(config1, false);
Telnet3270Client client = app.getClient();
assertNotNull(client);
// Force the client's FSM state to NOT_CONNECTED, simulating connection closure
client.getTelnetFSM().setConnectionState(haus.nightmare.lib3270j.ConnectionState.NOT_CONNECTED);
assertFalse(app.isConnected(), "app.isConnected() must return false when client is NOT_CONNECTED");
boolean[] handlerCalled = new boolean[]{false};
app.setConnectChoiceHandler((owner, target) -> {
handlerCalled[0] = true;
return ConnectChoiceDialog.Choice.CANCEL;
});
// Initiate a new connection
ConnectionConfig config2 = new ConnectionConfig("host2.test", 23, TerminalModel.IBM_3278_2);
app.connect(config2, true);
assertFalse(handlerCalled[0], "Connect choice handler must NOT be called when j3270 is not connected");
assertEquals("host2.test", app.getClient().getConfig().getHost(), "Must proceed to connect to host2.test in same window");
}
}