Skip to content

Commit

Permalink
Merge pull request #224 from oleg-nenashev/bug/JENKINS-46724-reflecti…
Browse files Browse the repository at this point in the history
…ve-operation-Launcher

[JENKINS-46724] - Get rid of the illegal Reflective operation in Launcher's checkTty()
  • Loading branch information
oleg-nenashev committed Nov 16, 2017
2 parents 40def98 + 8963035 commit 0b79eae
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/main/java/hudson/remoting/Launcher.java
Expand Up @@ -25,6 +25,8 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.remoting.Channel.Mode;

import java.io.Console;
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.nio.file.Path;
Expand Down Expand Up @@ -678,29 +680,19 @@ private void runWithStdinStdout() throws IOException, InterruptedException {
main(System.in, os, mode, ping, jarCache != null ? new FileSystemJarCache(jarCache,true) : null);
}

/**
* Checks if there is any {@link java.io.Console Console} object associated with JVM.
* If yes, prints a warning to STDOUT.
*/
private static void ttyCheck() {
try {
Method m = System.class.getMethod("console");
Object console = m.invoke(null);
if(console!=null) {
// we seem to be running from interactive console. issue a warning.
// but since this diagnosis could be wrong, go on and do what we normally do anyway. Don't exit.
System.out.println(
"WARNING: Are you running slave agent from an interactive console?\n" +
"If so, you are probably using it incorrectly.\n" +
"See http://wiki.jenkins-ci.org/display/JENKINS/Launching+slave.jar+from+from+console");
}
} catch (LinkageError e) {
// we are probably running on JDK5 that doesn't have System.console()
// we can't check
} catch (InvocationTargetException e) {
// this is impossible
throw new AssertionError(e);
} catch (NoSuchMethodException e) {
// must be running on JDK5
} catch (IllegalAccessException e) {
// this is impossible
throw new AssertionError(e);
final Console console = System.console();
if(console != null) {
// we seem to be running from interactive console. issue a warning.
// but since this diagnosis could be wrong, go on and do what we normally do anyway. Don't exit.
System.out.println(
"WARNING: Are you running slave agent from an interactive console?\n" +
"If so, you are probably using it incorrectly.\n" +
"See http://wiki.jenkins-ci.org/display/JENKINS/Launching+slave.jar+from+from+console");
}
}

Expand Down

0 comments on commit 0b79eae

Please sign in to comment.