[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,49 +9,19 @@
package java.lang; package java.lang;
import com.facebook.infer.builtins.InferBuiltins;
import com.facebook.infer.builtins.InferUndefined; import com.facebook.infer.builtins.InferUndefined;
import java.io.*; import java.io.FileDescriptor;
public abstract class Process { 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) { public Process(int pid, FileDescriptor in, FileDescriptor out, FileDescriptor err) {
this.pid = pid; InferBuiltins.__set_file_attribute(this);
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() { public void destroy() {
try { InferBuiltins.__set_mem_attribute(this);
inputStream.close();
} catch (IOException e) {}
try {
outputStream.close();
} catch (IOException e) {}
try {
errorStream.close();
} catch (IOException e) {}
} }
public Process destroyForcibly() { public Process destroyForcibly() {
@ -59,34 +29,4 @@ public abstract class Process {
return this; 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;
private ProcessOutputStream(FileDescriptor fd) {
super(fd);
this.fd = fd;
}
@Override
public void close() throws IOException {
super.close();
}
}
} }

@ -19,8 +19,7 @@ import java.lang.ref.WeakReference;
final class ProcessManager { abstract class ProcessManager {
public Process exec(String[] taintedCommand, String[] taintedEnvironment, File workingDirectory, public Process exec(String[] taintedCommand, String[] taintedEnvironment, File workingDirectory,
boolean redirectErrorStream) throws IOException { boolean redirectErrorStream) throws IOException {
@ -33,33 +32,13 @@ final class ProcessManager {
return process; return process;
} }
static class ProcessReference extends WeakReference<ProcessImpl> { public static native ProcessManager getInstance();
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 { static class ProcessImpl extends Process {
ProcessImpl(int pid, FileDescriptor in, FileDescriptor out, FileDescriptor err) { ProcessImpl(int pid, FileDescriptor in, FileDescriptor out, FileDescriptor err) {
super(pid, in, out, err); super(pid, in, out, err);
} }
void setExitValue(int exitValue) {
}
}
private static final ProcessManager instance = new ProcessManager();
public static ProcessManager getInstance() {
return instance;
} }
} }

Loading…
Cancel
Save