termux-packages
termux-packages copied to clipboard
openjdk-21: java can t use Runtime.exec
Problem description
For Android, posix_spawn fixed subprocess args first element equal to program path, when jdk call jspawnhelper, the first will override by the path then will be the issue. pls check this commit https://github.com/openjdk/mobile/commit/47d00a4cbeff5d757dda9c660dfd2385c02a57d7
What steps will reproduce the bug?
import java.io.IOException;
import java.io.File;
public class Main {
final static String test = "/system/bin/ls";
final static String workdir = "/data/data/com.termux/files/home";
public static void main(String[] args) {
final File dir = new File(workdir);
final ProcessBuilder pb = new ProcessBuilder(new String[]{test});
pb.directory(dir);
try {
final Process p = pb.start();
System.out.println(p.waitFor());
}
catch (Exception e) {
e.printStackTrace();
}
}
}
This command is not for general use and should only be run as the result of a call to
ProcessBuilder.start() or Runtime.exec() in a java application
java.io.IOException: Cannot run program "/system/bin/ls" (in directory "/data/data/com.termux/files/home"): error=0,
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1089)
at Main.main(Main.java:12)
Caused by: java.io.IOException: error=0,
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:295)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:225)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1126)
... 2 more
What is the expected behavior?
list home files.
System information
no need
openjdk-21 hasn't been packaged by Termux main repository. There is a WIP PR #20793