byte-buddy: Unable to install agent with IntelliJ bundled SDK on MacOS

When using Bytebuddy within IntelliJ and bundled Java 11 on MacOS it caused the following exception:

Caused by: java.io.IOException: Cannot run program ""/Applications/IntelliJ IDEA.app/Contents/jbr/Contents/Home/bin/java"": error=2, No such file or directory
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
    at net.bytebuddy.agent.ByteBuddyAgent.installExternal(ByteBuddyAgent.java:669)
    at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:601)
    ... 102 more

The culprit seems to be ByteBuddyAgent.java#L664

Additional Info:

IntelliJ Version 2019.3.1 (IU-193.5662.53)
bytebuddy 1.9.16

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 31 (14 by maintainers)

Commits related to this issue

Most upvoted comments

I am wondering - could we fix this by changing the quote function to only wrap quotes if the string it wraps does not contain quotes already? I guess this would add some implicit behaviour and may lead to side effects elsewhere… or we introduce a new method called quoteIfNotQuoted - you get the idea.

Alternatively, maybe replacing any whitespace characters with a path encoded equivalent might do the trick as well, have not tried it yet.

Weird. Currently I am experiencing the same issue as #732.

Environment: macOS 10.14.6

  • Idea 2019.2.3 with bundled Java 11. ($JAVA_HOME = /Applications/IntelliJ IDEA.app/Contents/jbr/Contents/Home)
  • Idea 2020.1.1 with Bundled Java 11 (same $JAVA_HOME).

Minimal reproducible example:

import java.io.*;

public class Main {
    private static String quote(String value) {
        return value.contains(" ")
                ? '"' + value + '"'
                : value;
    }
    public static void main(String[] args) throws IOException, InterruptedException {
        String s = System.getProperty("java.home");
        System.out.println(new ProcessBuilder(quote(s+"/bin/java")).start().waitFor());
    }
}
$ javac Main.java && java Main
Exception in thread "main" java.io.IOException: Cannot run program ""/Applications/IntelliJ IDEA.app/Contents/jbr/Contents/Home/bin/java"": error=2, No such file or directory
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
        at Main.main(Main.java:10)
Caused by: java.io.IOException: error=2, No such file or directory
        at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
        at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
        at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
        ... 2 more

Without the quote(), it runs fine.

I guess the newer version of Byte Buddy seems to work correctly. Once I updated the versions of mockk and Mockito (which use Byte Buddy), the problem disappeared.

Oh, and I guess this issue is a duplicate of that one: https://github.com/raphw/byte-buddy/issues/732, which is closed already.

Thanks, maybe it’s Java version dependant, too. Does it work if you quote it? Try an older release where the quoting is still applied.