Skip to content

Commit d0e7099

Browse files
committed
Fix an interesting errorprone warning about System.console() never
returning null. I opted to suppress the warning because the docs don't guarantee this but added isTerminal to detect non-terminal Console implementations. #15388
1 parent 9364ca2 commit d0e7099

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/scripts/StageArtifacts.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ static void requiresArgument(String[] args, int at) {
8080
}
8181
}
8282

83+
@SuppressWarnings("SystemConsoleNull")
8384
static Params parse(String[] args) {
8485
try {
8586
var params = new Params();
@@ -138,11 +139,12 @@ static Params parse(String[] args) {
138139
params.userPass = envVar("ASF_PASSWORD");
139140
if (params.userPass == null) {
140141
Console console = System.console();
141-
if (console != null) {
142+
if (console != null && console.isTerminal()) {
142143
System.out.println("Enter password for " + params.userName + ":");
143144
params.userPass = console.readPassword();
144145
} else {
145-
throw new RuntimeException("No console, can't prompt for password.");
146+
throw new RuntimeException(
147+
"No console or console isn't a terminal, can't prompt for password.");
146148
}
147149
}
148150
}

0 commit comments

Comments
 (0)