A DESCRIPTION OF THE REQUEST :
The java.lang.ProcessBuilder class needs a way to allow code to make a copy of an instance.
JUSTIFICATION :
Any immutable class that keeps a ProcessBuilder instance must maintain a private copy to ensure that the state does not change. To make this private copy, the code must manually clone the individual fields (commnd, directory, environment, and redirect property). This copy code is generally much cleaner when done in the class being copied.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would like to see a copy constructor provided on the java.lang.ProcessBuilder class. Properly implementing the java.lang.Cloneable interface would also suffice.
ACTUAL -
There is no method or constructor in the current ProcessBuilder class that can make a copy.
CUSTOMER SUBMITTED WORKAROUND :
final ProcessBuilder orig = ...
[...]
final ProcessBuilder clone = new ProcessBuilder();
clone.command(new java.util.ArrayList<String>(orig.command()));
clone.directory(orig.directory());
clone.environment().putAll(orig.environment());
clone.redirectErrorStream(orig.redirectErrorStream());
The java.lang.ProcessBuilder class needs a way to allow code to make a copy of an instance.
JUSTIFICATION :
Any immutable class that keeps a ProcessBuilder instance must maintain a private copy to ensure that the state does not change. To make this private copy, the code must manually clone the individual fields (commnd, directory, environment, and redirect property). This copy code is generally much cleaner when done in the class being copied.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would like to see a copy constructor provided on the java.lang.ProcessBuilder class. Properly implementing the java.lang.Cloneable interface would also suffice.
ACTUAL -
There is no method or constructor in the current ProcessBuilder class that can make a copy.
CUSTOMER SUBMITTED WORKAROUND :
final ProcessBuilder orig = ...
[...]
final ProcessBuilder clone = new ProcessBuilder();
clone.command(new java.util.ArrayList<String>(orig.command()));
clone.directory(orig.directory());
clone.environment().putAll(orig.environment());
clone.redirectErrorStream(orig.redirectErrorStream());