db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Zaun (JIRA)" <j...@apache.org>
Subject [jira] Updated: (DERBY-3543) NetworkServerControl with user password but no command does not give usage message
Date Wed, 19 Mar 2008 22:36:24 GMT

     [ https://issues.apache.org/jira/browse/DERBY-3543?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Martin Zaun updated DERBY-3543:
-------------------------------

    Attachment: DERBY-3542-0_experimental.diff
                DERBY-3542-0_experimental.stat


Having had a closer look into this issue, I'm attaching an experimental patch for comments
(I quickly tested the patch but did not run any test suites).

As stated above, this issue is unrelated to DERBY-2109: The usage text is not printed if any
command-line argument has been given, even if a command is still missing.

For instance:
    java org.apache.derby.drda.NetworkServerControl
prints the usage text while
    java org.apache.derby.drda.NetworkServerControl -h localhost
does not.

The patch results changes the behaviour to that a usage message is always printed when no
command has been given, regardless of whether any options have been specified.

There are a number of finepoints described below.

--------------------------------------------------------------------------------------

First, there is a swallowed exception, I'd call it a bug, in method NetworkServerControlImpl.findCommand(String[]),
around line 2145:
			// didn't find command
			consolePropertyMessage("DRDA_UnknownCommand.U", 
				(String) commandArgs.firstElement());

a) When no actual command was given, the Vector commandArgs is still empty.
b) It then happens that commandArgs.firstElement() throws a NoSuchElementException.
c) Unfortunately, this exception is swallowed by the following catch clause:
		} catch (Exception e) {
			if (e.getMessage().equals(NetworkServerControlImpl.UNEXPECTED_ERR))
				throw e;
			//Ignore expected exceptions, they will have been
									//handled by the consolePropertyMessage routine
		}

A fix is very simple: move a closing brace "}" a few lines down, so that the block structure
becomes:
			if (commandArgs.size() > 0)
			{
				...

				// didn't find command
				consolePropertyMessage("DRDA_UnknownCommand.U", 
					(String) commandArgs.firstElement());
			}

When no actual command was given, the block is not executed.

The method findCommand(String[]) ends with:
		return COMMAND_UNKNOWN;

--------------------------------------------------------------------------------------

Second, and more importantly, the method NetworkServerControlImpl.parseArgs(String[]) shows
some twisted logic:

        int command = COMMAND_START; 
        if (args.length > 0)
            command = findCommand(args);
        else
        {
            consolePropertyMessage("DRDA_NoArgs.U");
        }
        return command;

a) It assigns a default command ("start").

b) However, if no command (or option) it calls
            consolePropertyMessage("DRDA_NoArgs.U");
   which prints a usage message and EXITS -- as I've found out to my surprise.  I didn't expect
a method named  consolePropertyMessage() to have such dramatic side-effects.

c) The usage message clearly indicates that there's no default command:

Usage: NetworkServerControl <commands>
Commands:
start [-h <host>] [-p <portnumber>] [-noSecurityManager] [-ssl <sslmode>]
shutdown [-h <host>][-p <portnumber>] [-ssl <sslmode>] [-user <username>]
[-pass
word <password>]
ping [-h <host>][-p <portnumber>] [-ssl <sslmode>]
sysinfo [-h <host>][-p <portnumber>] [-ssl <sslmode>]
runtimeinfo [-h <host>][-p <portnumber>] [-ssl <sslmode>]
logconnections {on|off}[-h <host>][-p <portnumber>] [-ssl <sslmode>]
maxthreads <max>[-h <host>][-p <portnumber>] [-ssl <sslmode>]
timeslice <milliseconds>[-h <host>][-p <portnumber>] [-ssl <sslmode>]
trace {on|off} [-s <session id>][-h <host>][-p <portnumber>] [-ssl <sslmode>]
tracedirectory <traceDirectory>[-h <host>][-p <portnumber>] [-ssl <sslmode>]

d) If, however, any command-line argument was given and findCommand() runs into any problems
it returns COMMAND_UNKNOWN, in which case the assigned default command has got overridden.


To summarize: Perhaps, there once was such a thing as a default command ("start") in the past,
but points b), c), and d) indicate to me that this has not been supported for a while.

So, under the assumption that users MUST provide a command to NetworkServerControl and if
they have not done so that
- a usage message is to be printed regardless of whether additional options were provided
or not and
- NetworkServerControl should then exit
the method parseArgs(String[]) can be nicely cleaned up and implemented as:

        int command = findCommand(args);
        if (command == COMMAND_UNKNOWN)
        {
            consolePropertyMessage("DRDA_NoArgs.U");
        }
        return command;

--------------------------------------------------------------------------------------


> NetworkServerControl with user password but no command does not give usage message
> ----------------------------------------------------------------------------------
>
>                 Key: DERBY-3543
>                 URL: https://issues.apache.org/jira/browse/DERBY-3543
>             Project: Derby
>          Issue Type: Bug
>          Components: Network Server
>    Affects Versions: 10.4.1.0, 10.5.0.0
>            Reporter: Kathey Marsden
>            Priority: Minor
>         Attachments: DERBY-3542-0_experimental.diff, DERBY-3542-0_experimental.stat
>
>
> I noticed that 
> java org.apache.derby.drda.NetworkServerControl  -user mary -password mypass
> with no actual command just completes with no usage message.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message