diff --git a/infer/models/java/src/java/lang/Process.java b/infer/models/java/src/java/lang/Process.java index 2892a6b88..5034a6d3b 100644 --- a/infer/models/java/src/java/lang/Process.java +++ b/infer/models/java/src/java/lang/Process.java @@ -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; + } } diff --git a/infer/models/java/src/java/lang/ProcessManager.java b/infer/models/java/src/java/lang/ProcessManager.java index 1c7b69621..8537247d1 100644 --- a/infer/models/java/src/java/lang/ProcessManager.java +++ b/infer/models/java/src/java/lang/ProcessManager.java @@ -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 { - - final int processId; - - public ProcessReference(ProcessImpl referent, ProcessReferenceQueue referenceQueue) { - super(referent, referenceQueue); - this.processId = referent.pid; - } - } - - static class ProcessReferenceQueue extends ReferenceQueue { - } - - 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); } + } } diff --git a/infer/models/java/src/java/lang/Runtime.java b/infer/models/java/src/java/lang/Runtime.java index 88166367e..3694ba8e3 100644 --- a/infer/models/java/src/java/lang/Runtime.java +++ b/infer/models/java/src/java/lang/Runtime.java @@ -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); + } }