Different results when running Java program inside Intellij

Answered

Intellij IDEA 2021.2 (Community Edition) under Linux Mint 20.2

This problem started with the Runtime.getRuntime().exec() method always returning "error=2, unknown file" for some executables under /usr/bin. For example, I can getRuntime().exec( "/usr/bin/ls") just fine, but I can't exec /usr/bin/lp without errors. File permissions, ownership, and file type are the same for both programs.

After some debugging, I found that this problem also affected the java File object. When the following program is run from Intellij IDE, the file is not found. But if compiled and run externally, it is.

What's going on here?


Program Listing: Note: The Intellij program had a package declaration, the external version doesn't.
============

import java.io.File;

public class FileUnknownError
{
static void checkFile( String fName)
{
File f = new File( fName);
System.out.printf( "Checking File: '%s'\n", fName);
System.out.printf( " Exists: '%b'\n", f.exists());
System.out.printf( " Is File: '%b'\n", f.isFile());
System.out.printf( " Is Absolute: '%b'\n", f.isAbsolute());
System.out.printf( " Can Read: '%b'\n", f.canRead());
System.out.printf( " Can Write: '%b'\n", f.canWrite());
System.out.printf( " Can Execute: '%b'\n", f.canExecute());
}

public static void main( String[] args)
throws Throwable
{
String fName = "/usr/bin/lp";
checkFile( fName);
}
}


Output from Intellij:
==============

Checking File:          '/usr/bin/lp'
Exists: 'false'
Is File: 'false'
Is Absolute: 'true'
Can Read: 'false'
Can Write: 'false'
Can Execute: 'false'


Output from external running
======================

Checking File:          '/usr/bin/lp'
Exists: 'true'
Is File: 'true'
Is Absolute: 'true'
Can Read: 'true'
Can Write: 'false'
Can Execute: 'true'
0
3 comments

If you installed IntelliJ IDEA via snaps, reinstall it from the tar.gz instead: https://www.jetbrains.com/idea/download/index.html .

snap environment is isolated and can limit access to certain directories and executable files.

0

Snaps is disabled on Mint 20.2 because Ubuntu and Mint are squabbling over some ideological issue.  Intellij was installed via flatpak.  But flatpak is similar to snaps and appears to have the same issue.

From what you say, snap and flatpak are selectively ignoring /usr/bin executables because /usr/bin/ls works fine from Intellij.  If I copy (links don't work) the /usr/bin executable to my home directory, Intellij will run it just fine.  Whether it works correctly is another matter.

I think I'll go over to flatpak and see what they have to say.  And its time to dump the flatpak version of Intellij.

Thx for the info.

0

Please note that flatpack is not even an officially supported IntelliJ IDEA package.

0

Please sign in to leave a comment.