Skip to content

Commit

Permalink
Merge pull request #261 from ZeroErrors/master
Browse files Browse the repository at this point in the history
Fix reflection in TerminalBuilder getParentProcessCommand()
  • Loading branch information
gnodet authored May 4, 2018
2 parents 6cc608c + 62132ff commit c5f68dd
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Optional;
Expand Down Expand Up @@ -411,11 +412,12 @@ private Terminal doBuild() throws IOException {

private static String getParentProcessCommand() {
try {
Class<?> phClass = Class.forName("java.lang.ProcessHandler");
Class<?> phClass = Class.forName("java.lang.ProcessHandle");
Object current = phClass.getMethod("current").invoke(null);
Object parent = ((Optional<?>) phClass.getMethod("parent").invoke(current)).orElse(null);
Object info = phClass.getMethod("info").invoke(parent);
Object command = ((Optional<?>) info.getClass().getMethod("command").invoke(info)).orElse(null);
Method infoMethod = phClass.getMethod("info");
Object info = infoMethod.invoke(parent);
Object command = ((Optional<?>) infoMethod.getReturnType().getMethod("command").invoke(info)).orElse(null);
return (String) command;
} catch (Throwable t) {
return null;
Expand Down

0 comments on commit c5f68dd

Please sign in to comment.