8006298: Specifying malformed JFR options (-XX:+FlightRecorderOptions) outputs non-sensical error

Change error messages for malformed options so the messages are more useful.

Reviewed-by: mikael, kvn, nloodin
This commit is contained in:
Harold Seigel 2013-02-01 14:14:54 -05:00
parent 733d5fdd65
commit a2966dd62d

View File

@ -827,7 +827,8 @@ bool Arguments::process_argument(const char* arg,
return true; return true;
} }
const char * const argname = *arg == '+' || *arg == '-' ? arg + 1 : arg; bool has_plus_minus = (*arg == '+' || *arg == '-');
const char* const argname = has_plus_minus ? arg + 1 : arg;
if (is_newly_obsolete(arg, &since)) { if (is_newly_obsolete(arg, &since)) {
char version[256]; char version[256];
since.to_string(version, sizeof(version)); since.to_string(version, sizeof(version));
@ -838,13 +839,29 @@ bool Arguments::process_argument(const char* arg,
// For locked flags, report a custom error message if available. // For locked flags, report a custom error message if available.
// Otherwise, report the standard unrecognized VM option. // Otherwise, report the standard unrecognized VM option.
Flag* locked_flag = Flag::find_flag((char*)argname, strlen(argname), true); size_t arg_len;
if (locked_flag != NULL) { const char* equal_sign = strchr(argname, '=');
if (equal_sign == NULL) {
arg_len = strlen(argname);
} else {
arg_len = equal_sign - argname;
}
Flag* found_flag = Flag::find_flag((char*)argname, arg_len, true);
if (found_flag != NULL) {
char locked_message_buf[BUFLEN]; char locked_message_buf[BUFLEN];
locked_flag->get_locked_message(locked_message_buf, BUFLEN); found_flag->get_locked_message(locked_message_buf, BUFLEN);
if (strlen(locked_message_buf) == 0) { if (strlen(locked_message_buf) == 0) {
if (found_flag->is_bool() && !has_plus_minus) {
jio_fprintf(defaultStream::error_stream(), jio_fprintf(defaultStream::error_stream(),
"Unrecognized VM option '%s'\n", argname); "Missing +/- setting for VM option '%s'\n", argname);
} else if (!found_flag->is_bool() && has_plus_minus) {
jio_fprintf(defaultStream::error_stream(),
"Unexpected +/- setting in VM option '%s'\n", argname);
} else {
jio_fprintf(defaultStream::error_stream(),
"Improperly specified VM option '%s'\n", argname);
}
} else { } else {
jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf); jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
} }