8296684: Improve String platform support

Reviewed-by: amenkov, michaelm, rhalade
This commit is contained in:
Kevin Walls 2023-01-18 21:29:57 +00:00 committed by Henry Jen
parent 14aad787a8
commit b1c34c03d7
5 changed files with 14 additions and 0 deletions

View File

@ -136,6 +136,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
*/
InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
assert args.length <= 3; // includes null
checkNulls(args);
// did we detach?
synchronized (this) {

View File

@ -140,6 +140,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
*/
InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
assert args.length <= 3; // includes null
checkNulls(args);
// did we detach?
synchronized (this) {

View File

@ -136,6 +136,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
*/
InputStream execute(String cmd, Object ... args) throws AgentLoadException, IOException {
assert args.length <= 3; // includes null
checkNulls(args);
// did we detach?
synchronized (this) {

View File

@ -487,4 +487,14 @@ public abstract class HotSpotVirtualMachine extends VirtualMachine {
}
return attachTimeout;
}
protected static void checkNulls(Object... args) {
for (Object arg : args) {
if (arg instanceof String s) {
if (s.indexOf(0) >= 0) {
throw new IllegalArgumentException("illegal null character in command");
}
}
}
}
}

View File

@ -73,6 +73,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
throws AgentLoadException, IOException
{
assert args.length <= 3; // includes null
checkNulls(args);
// create a pipe using a random name
Random rnd = new Random();