< prev index next >

src/java.base/share/classes/sun/security/util/ConsoleCallbackHandler.java

Print this page
rev 52881 : 8214971: Replace use of string.equals("") with isEmpty()
Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad


  86                 String message = tc.getMessage();
  87                 if (message != null) {
  88                     text += message;
  89                 }
  90                 if (text != null) {
  91                     System.err.println(text);
  92                 }
  93 
  94             } else if (callbacks[i] instanceof NameCallback) {
  95                 NameCallback nc = (NameCallback) callbacks[i];
  96 
  97                 if (nc.getDefaultName() == null) {
  98                     System.err.print(nc.getPrompt());
  99                 } else {
 100                     System.err.print(nc.getPrompt() +
 101                                 " [" + nc.getDefaultName() + "] ");
 102                 }
 103                 System.err.flush();
 104 
 105                 String result = readLine();
 106                 if (result.equals("")) {
 107                     result = nc.getDefaultName();
 108                 }
 109 
 110                 nc.setName(result);
 111 
 112             } else if (callbacks[i] instanceof PasswordCallback) {
 113                 PasswordCallback pc = (PasswordCallback) callbacks[i];
 114 
 115                 System.err.print(pc.getPrompt());
 116                 System.err.flush();
 117 
 118                 pc.setPassword(Password.readPassword(System.in, pc.isEchoOn()));
 119 
 120             } else if (callbacks[i] instanceof ConfirmationCallback) {
 121                 confirmation = (ConfirmationCallback) callbacks[i];
 122 
 123             } else {
 124                 throw new UnsupportedCallbackException(
 125                     callbacks[i], "Unrecognized Callback");
 126             }


 195             break;
 196         case ConfirmationCallback.UNSPECIFIED_OPTION:
 197             String[] optionStrings = confirmation.getOptions();
 198             options = new OptionInfo[optionStrings.length];
 199             for (int i = 0; i < options.length; i++) {
 200                 options[i] = new OptionInfo(optionStrings[i], i);
 201             }
 202             break;
 203         default:
 204             throw new UnsupportedCallbackException(
 205                 confirmation, "Unrecognized option type: " + optionType);
 206         }
 207 
 208         int defaultOption = confirmation.getDefaultOption();
 209 
 210         String prompt = confirmation.getPrompt();
 211         if (prompt == null) {
 212             prompt = "";
 213         }
 214         prompt = prefix + prompt;
 215         if (!prompt.equals("")) {
 216             System.err.println(prompt);
 217         }
 218 
 219         for (int i = 0; i < options.length; i++) {
 220             if (optionType == ConfirmationCallback.UNSPECIFIED_OPTION) {
 221                 // defaultOption is an index into the options array
 222                 System.err.println(
 223                     i + ". " + options[i].name +
 224                     (i == defaultOption ? " [default]" : ""));
 225             } else {
 226                 // defaultOption is an option value
 227                 System.err.println(
 228                     i + ". " + options[i].name +
 229                     (options[i].value == defaultOption ? " [default]" : ""));
 230             }
 231         }
 232         System.err.print("Enter a number: ");
 233         System.err.flush();
 234         int result;
 235         try {


  86                 String message = tc.getMessage();
  87                 if (message != null) {
  88                     text += message;
  89                 }
  90                 if (text != null) {
  91                     System.err.println(text);
  92                 }
  93 
  94             } else if (callbacks[i] instanceof NameCallback) {
  95                 NameCallback nc = (NameCallback) callbacks[i];
  96 
  97                 if (nc.getDefaultName() == null) {
  98                     System.err.print(nc.getPrompt());
  99                 } else {
 100                     System.err.print(nc.getPrompt() +
 101                                 " [" + nc.getDefaultName() + "] ");
 102                 }
 103                 System.err.flush();
 104 
 105                 String result = readLine();
 106                 if (result.isEmpty()) {
 107                     result = nc.getDefaultName();
 108                 }
 109 
 110                 nc.setName(result);
 111 
 112             } else if (callbacks[i] instanceof PasswordCallback) {
 113                 PasswordCallback pc = (PasswordCallback) callbacks[i];
 114 
 115                 System.err.print(pc.getPrompt());
 116                 System.err.flush();
 117 
 118                 pc.setPassword(Password.readPassword(System.in, pc.isEchoOn()));
 119 
 120             } else if (callbacks[i] instanceof ConfirmationCallback) {
 121                 confirmation = (ConfirmationCallback) callbacks[i];
 122 
 123             } else {
 124                 throw new UnsupportedCallbackException(
 125                     callbacks[i], "Unrecognized Callback");
 126             }


 195             break;
 196         case ConfirmationCallback.UNSPECIFIED_OPTION:
 197             String[] optionStrings = confirmation.getOptions();
 198             options = new OptionInfo[optionStrings.length];
 199             for (int i = 0; i < options.length; i++) {
 200                 options[i] = new OptionInfo(optionStrings[i], i);
 201             }
 202             break;
 203         default:
 204             throw new UnsupportedCallbackException(
 205                 confirmation, "Unrecognized option type: " + optionType);
 206         }
 207 
 208         int defaultOption = confirmation.getDefaultOption();
 209 
 210         String prompt = confirmation.getPrompt();
 211         if (prompt == null) {
 212             prompt = "";
 213         }
 214         prompt = prefix + prompt;
 215         if (!prompt.isEmpty()) {
 216             System.err.println(prompt);
 217         }
 218 
 219         for (int i = 0; i < options.length; i++) {
 220             if (optionType == ConfirmationCallback.UNSPECIFIED_OPTION) {
 221                 // defaultOption is an index into the options array
 222                 System.err.println(
 223                     i + ". " + options[i].name +
 224                     (i == defaultOption ? " [default]" : ""));
 225             } else {
 226                 // defaultOption is an option value
 227                 System.err.println(
 228                     i + ". " + options[i].name +
 229                     (options[i].value == defaultOption ? " [default]" : ""));
 230             }
 231         }
 232         System.err.print("Enter a number: ");
 233         System.err.flush();
 234         int result;
 235         try {
< prev index next >