[infer][java] simplify the process of java.lang.Process

Summary: This is to prevent test failures to happen whenchanging the code a little.

Reviewed By: sblackshear

Differential Revision: D5815349

fbshipit-source-id: 8516102
master
Jeremy Dubreil 7 years ago committed by Facebook Github Bot
parent 5f176f40e3
commit bb85b24f0a

@ -9,84 +9,24 @@
package java.lang;
import com.facebook.infer.builtins.InferBuiltins;
import com.facebook.infer.builtins.InferUndefined;
import java.io.*;
import java.io.FileDescriptor;
public abstract class Process {
protected final int pid;
protected final InputStream inputStream;
protected final OutputStream outputStream;
protected final InputStream errorStream;
public Process(int pid, FileDescriptor in, FileDescriptor out, FileDescriptor err) {
this.pid = pid;
this.inputStream = new ProcessInputStream(in);
this.outputStream = new ProcessOutputStream(out);
this.errorStream = new ProcessInputStream(err);
}
public int exitValue() {
return InferUndefined.int_undefined();
}
public InputStream getInputStream() {
return this.inputStream;
}
public OutputStream getOutputStream() {
return this.outputStream;
}
public int waitFor() throws InterruptedException {
return InferUndefined.int_undefined();
}
public void destroy() {
try {
inputStream.close();
} catch (IOException e) {}
try {
outputStream.close();
} catch (IOException e) {}
try {
errorStream.close();
} catch (IOException e) {}
}
public Process destroyForcibly() {
destroy();
return this;
}
private static class ProcessInputStream extends FileInputStream {
private FileDescriptor fd;
private ProcessInputStream(FileDescriptor fd) {
super(fd);
this.fd = fd;
}
@Override
public void close() throws IOException {
super.close();
}
}
private static class ProcessOutputStream extends FileOutputStream {
private FileDescriptor fd;
InferBuiltins.__set_file_attribute(this);
}
private ProcessOutputStream(FileDescriptor fd) {
super(fd);
this.fd = fd;
}
public void destroy() {
InferBuiltins.__set_mem_attribute(this);
}
@Override
public void close() throws IOException {
super.close();
}
}
public Process destroyForcibly() {
destroy();
return this;
}
}

@ -19,47 +19,26 @@ import java.lang.ref.WeakReference;
final class ProcessManager {
abstract class ProcessManager {
public Process exec(String[] taintedCommand, String[] taintedEnvironment, File workingDirectory,
boolean redirectErrorStream) throws IOException {
public Process exec(String[] taintedCommand, String[] taintedEnvironment, File workingDirectory,
boolean redirectErrorStream) throws IOException {
FileDescriptor in = new FileDescriptor();
FileDescriptor out = new FileDescriptor();
FileDescriptor err = new FileDescriptor();
FileDescriptor in = new FileDescriptor();
FileDescriptor out = new FileDescriptor();
FileDescriptor err = new FileDescriptor();
ProcessImpl process = new ProcessImpl(InferUndefined.int_undefined(), in, out, err);
return process;
}
ProcessImpl process = new ProcessImpl(InferUndefined.int_undefined(), in, out, err);
return process;
}
static class ProcessReference extends WeakReference<ProcessImpl> {
final int processId;
public ProcessReference(ProcessImpl referent, ProcessReferenceQueue referenceQueue) {
super(referent, referenceQueue);
this.processId = referent.pid;
}
}
static class ProcessReferenceQueue extends ReferenceQueue<ProcessImpl> {
}
static class ProcessImpl extends Process {
ProcessImpl(int pid, FileDescriptor in, FileDescriptor out, FileDescriptor err) {
super(pid, in, out, err);
}
void setExitValue(int exitValue) {
}
}
public static native ProcessManager getInstance();
private static final ProcessManager instance = new ProcessManager();
static class ProcessImpl extends Process {
public static ProcessManager getInstance() {
return instance;
ProcessImpl(int pid, FileDescriptor in, FileDescriptor out, FileDescriptor err) {
super(pid, in, out, err);
}
}
}

@ -15,33 +15,33 @@ import java.io.IOException;
public class Runtime {
private Runtime() {
}
public Process exec(String command) throws IOException {
return exec(command, null, null);
}
public Process exec(String command, String[] envp) throws IOException {
return exec(command, envp, null);
}
public Process exec(String command, String[] envp, File dir)
throws IOException {
return ProcessManager.getInstance().exec(null, envp, null, false);
}
public Process exec(String cmdarray[]) throws IOException {
return exec(cmdarray, null, null);
}
public Process exec(String[] cmdarray, String[] envp) throws IOException {
return exec(cmdarray, envp, null);
}
public Process exec(String[] cmdarray, String[] envp, File dir)
throws IOException {
return ProcessManager.getInstance().exec(cmdarray, envp, dir, false);
}
private Runtime() {
}
public Process exec(String command) throws IOException {
return exec(command, null, null);
}
public Process exec(String command, String[] envp) throws IOException {
return exec(command, envp, null);
}
public Process exec(String command, String[] envp, File dir)
throws IOException {
return ProcessManager.getInstance().exec(null, envp, null, false);
}
public Process exec(String cmdarray[]) throws IOException {
return exec(cmdarray, null, null);
}
public Process exec(String[] cmdarray, String[] envp) throws IOException {
return exec(cmdarray, envp, null);
}
public Process exec(String[] cmdarray, String[] envp, File dir)
throws IOException {
return ProcessManager.getInstance().exec(cmdarray, envp, dir, false);
}
}

Loading…
Cancel
Save