[
https://issues.jboss.org/browse/WFCORE-1417?page=com.atlassian.jira.plugi...
]
Tom Fonteyne edited comment on WFCORE-1417 at 3/1/16 7:54 AM:
--------------------------------------------------------------
not sure what the correct solution would be....
either for every applicable connect:
{code:java}
public void connect() {
checkAlreadyConnected();
try {
ctx = CommandContextFactory.getInstance().newCommandContext();
ctx.connectController();
} catch (CliInitializationException e) {
ctx = null;
throw new IllegalStateException("Unable to initialize command
context.", e);
} catch (CommandLineException e) {
ctx = null;
throw new IllegalStateException("Unable to connect to controller.",
e);
}
}
{code}
or:
{code:java}
public void terminateSession() {
try {
ctx.terminateSession();
} finally {
ctx = null;
}
}
{code}
and for every applicable connect:
{code:java}
public void connect() {
checkAlreadyConnected();
try {
ctx = CommandContextFactory.getInstance().newCommandContext();
ctx.connectController();
} catch (CliInitializationException e) {
terminateSession();
throw new IllegalStateException("Unable to initialize command
context.", e);
} catch (CommandLineException e) {
terminateSession();
throw new IllegalStateException("Unable to connect to controller.",
e);
}
}
{code}
was (Author: tfonteyn):
not sure what the correct solution would be....
either for every applicable connect:
public void connect() {
checkAlreadyConnected();
try {
ctx = CommandContextFactory.getInstance().newCommandContext();
ctx.connectController();
} catch (CliInitializationException e) {
ctx = null;
throw new IllegalStateException("Unable to initialize command
context.", e);
} catch (CommandLineException e) {
ctx = null;
throw new IllegalStateException("Unable to connect to controller.",
e);
}
}
or:
public void terminateSession() {
try {
ctx.terminateSession();
} finally {
ctx = null;
}
}
and for every applicable connect:
public void connect() {
checkAlreadyConnected();
try {
ctx = CommandContextFactory.getInstance().newCommandContext();
ctx.connectController();
} catch (CliInitializationException e) {
terminateSession();
throw new IllegalStateException("Unable to initialize command
context.", e);
} catch (CommandLineException e) {
terminateSession();
throw new IllegalStateException("Unable to connect to controller.",
e);
}
}
org.jboss.as.cli.scriptsupport.CLI connect methods do not properly
reset the ctx upon failure making in turn checkNotConnected() to report incorrectly
------------------------------------------------------------------------------------------------------------------------------------------------------
Key: WFCORE-1417
URL:
https://issues.jboss.org/browse/WFCORE-1417
Project: WildFly Core
Issue Type: Bug
Components: CLI
Affects Versions: 2.1.0.CR1
Reporter: Tom Fonteyne
Assignee: Alexey Loubyansky
Priority: Minor
cli/src/main/java/org/jboss/as/cli/scriptsupport/CLI.java
public void connect() {
checkAlreadyConnected();
try {
ctx = CommandContextFactory.getInstance().newCommandContext();
ctx.connectController();
} catch (CliInitializationException e) {
throw new IllegalStateException("Unable to initialize command
context.", e);
} catch (CommandLineException e) {
throw new IllegalStateException("Unable to connect to controller.",
e);
}
}
also applicable to the other connects of course.
If the connection fails in the connect method, a subsequent connect will hit:
private void checkAlreadyConnected() {
if (ctx != null) throw new IllegalStateException("Already connected to
server.");
}
and will fail for the wrong reason... as while ctx !=null is true, but the connection had
failed.
ergo, upon failure in connect, the ctx should be reset to avoid this
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)