Browse Source

throw exception with useful message if input handler hits EOF

master
Stefan Bodewig 7 years ago
parent
commit
f443a85b92
3 changed files with 16 additions and 1 deletions
  1. +4
    -0
      WHATSNEW
  2. +3
    -0
      src/main/org/apache/tools/ant/input/DefaultInputHandler.java
  3. +9
    -1
      src/main/org/apache/tools/ant/input/SecureInputHandler.java

+ 4
- 0
WHATSNEW View File

@@ -28,6 +28,10 @@ Fixed bugs:
* The junit task when used with includeantruntime="no" was incorrectly
printing a warning about multiple versions of ant detected in path

* Default and SecureInputHandler will now raise an error when then
end of the inout stream (usually System.in or System.console) are
reached before a valid input has been read.

Other changes:
--------------



+ 3
- 0
src/main/org/apache/tools/ant/input/DefaultInputHandler.java View File

@@ -56,6 +56,9 @@ public class DefaultInputHandler implements InputHandler {
System.err.flush();
try {
String input = r.readLine();
if (input == null) {
throw new BuildException("unexpected end of stream while reading input");
}
request.setInput(input);
} catch (IOException e) {
throw new BuildException("Failed to read input from"


+ 9
- 1
src/main/org/apache/tools/ant/input/SecureInputHandler.java View File

@@ -40,6 +40,7 @@ public class SecureInputHandler extends DefaultInputHandler {
* @throws BuildException if not possible to read from console
*/
public void handleInput(InputRequest request) throws BuildException {
boolean nullInput = false;
String prompt = getPrompt(request);
try {
Object console = ReflectUtil.invokeStatic(System.class, "console");
@@ -47,6 +48,10 @@ public class SecureInputHandler extends DefaultInputHandler {
char[] input = (char[]) ReflectUtil.invoke(
console, "readPassword", String.class, prompt,
Object[].class, (Object[]) null);
if (input == null) {
nullInput = true;
break;
}
request.setInput(new String(input));
/* for security zero char array after retrieving value */
java.util.Arrays.fill(input, ' ');
@@ -55,5 +60,8 @@ public class SecureInputHandler extends DefaultInputHandler {
/* Java6 not present use default handler */
super.handleInput(request);
}
if (nullInput) {
throw new BuildException("unexpected end of stream while reading input");
}
}
}
}

Loading…
Cancel
Save