Can't run a subprocess with a program in /usr/bin from a Gradle build

Consider the following example;

import java.io.*;
import java.lang.*;

class test {
  public static void main(String[] args) throws IOException {
    ProcessBuilder pb = new ProcessBuilder("/usr/bin/alacritty");
    pb.start();
  }
}

This code, run with java test.java, opens the target program

Now, consider the same code snippet, but run from this Gradle build
This second example, the same code, runs into this error;

java.security.PrivilegedActionException: java.security.PrivilegedActionException: java.io.IOException: Cannot run program "/usr/bin/alacritty": error=2, No such file or directory
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

We can rule out this “No such file or directory” as the first example, opening the same program, worked

I’m lost on what could be the cause. I’m using the same direct path in both examples, so it’s not a problem with environments (although they are different quite different, both include /usr/bin)

Hi,

I tried your sample, and it works fine here:

src/main/test.java

public class test {

	public static void main(String... args) throws Exception {
		ProcessBuilder builder = new ProcessBuilder("/usr/bin/alacritty");
		// Required because my GPU does not meet requirements otherwise
		builder.environment().put("LIBGL_ALWAYS_SOFTWARE", "1");
		builder.start();
	}
}

build.gradle

plugins {
	id 'application'
}

application {
	mainClass = 'test'
}

Both executions open the terminal and immediately return:

/tmp/foo$ alacritty --version
alacritty 0.8.0 (a1b13e68)
/tmp/foo$ ./gradlew --version
------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------
[...]
JVM:          11.0.11 (Oracle Corporation 11.0.11+9)
[...]

/tmp/foo$ java --version
openjdk 11.0.11 2021-04-20
[...]
/tmp/foo$ java src/main/java/test.java
/tmp/foo$ echo $?
0
/tmp/foo$ ./gradlew run

BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed
/tmp/foo$ echo $?
0

There must be something else related to your environment that prevents the process to start.
It could be worth trying to disable most of user specific programs, scripts running automatically when the terminal spawns (bashrc, profile, …). Maybe by creating a new user from scratch on your environment. It could help you narrowing the issue.

If your example works for you, then this is probably a problem with my machine specifically. I just set up a new Gradle build with the minimal build.gradle you gave and the same code snippet and it results in the same error I was getting with my main project

Edit: I’ve done a complete reinstall of my distro (PopOS) and the issue is persisting. I’ll try with another distro

Edit: Installed Ubuntu Budgie, no more error. I guess it’s a PopOS bug?