JabRef--master--latest.jar (https://builds.jabref.org/master/) as well as version 4.3.1-2 form Arch AUR (https://aur.archlinux.org/packages/jabref/)
Right clicking on any entry in any database and selecting "Open folder" results in the NullPointer exception below. The setup experiencing this problem is Arch Linux with i3 window manager and without desktop environment. Hence it could be that there is a dependency to some external SW that is not satisfied. This problem exists over multiple version already (~1y) over different Arch machines I operate. My guess is that there is some unknown dependency that I lack on my systems, which causes "open folder" to silently crash. I would be interested in tracking down what exactly is causing that issue. Might be something very obvious to you guys.
Steps to reproduce the behavior:
Log File
10:51:41.270 [JabRef CachedThreadPool] ERROR org.jabref.FallbackExceptionHandler - Uncaught exception occurred in Thread[JabRef CachedThreadPool,5,main]
java.lang.NullPointerException: null
at org.jabref.gui.desktop.os.Linux.openFolderAndSelectFile(Linux.java:54) ~[JabRef--master--latest.jar:?]
at org.jabref.gui.desktop.JabRefDesktop.openFolderAndSelectFile(JabRefDesktop.java:171) ~[JabRef--master--latest.jar:?]
at org.jabref.gui.BasePanel.lambda$null$49(BasePanel.java:348) ~[JabRef--master--latest.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_201]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_201]
Used Java version:
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
I'm happy to provide further details!
I am able to reproduce this on my setup (same as that of the author).
Could you please tell what the expected behavior is, should it open the folder, in a file explorer, where the file resides?
@CaptainDaVinci It should open the default file manager of the OS and select the file.
e.g. on Windows it opens the explorer and selects the file:
(The file is not related to the entry, just for demonstration purposes)

@pirius It seems like this is a classical NPE because the environment variable DESKTOP_SESSION is not set. I'm not a Linux expert, so you may have an idea for a better implementation:
For setups using window managers (e.g i3) instead of desktop environments (e.g KDE), there aren't any out-of-the box file explorers provided. I think many users having a similar setup prefer not to have a GUI file explorer. Instead we could, maybe, open the terminal where the file resides?
Sounds like a good idea. There should already be a method for opening the terminal. So the easiest way would be to wrap the System.getEnv call in an optional.ofNullable and then open the terminal if not present
@Siedlerchr now I understand. I neither have nautilus installed nor is my DESKTOP_SESSION set. My suggestion would be:
in the preferences in external programs give an option for which command is executed when "open folder" is selected. This way on Linux you would not be bound to any specific file browser. You could include the path to the file selected in JabRef as a variable in that command: this way users would be able to choose where in the command the path to the selected file is used. This is similar to how e.g. Kile handles external programs like file browsers, pdf vieweres, etc, should you be familiar with Kile.
in situations where you need to anyway rely on those external environment variables and external programs to be present, maybe make the exception descriptive. I just realized with the code above that setting my DESKTOP_SESSION and installing Nautilus or similar might have solved the problem :)
I would not recommend on hard coding any terminal - this would lead to similar issues as with file browsers (people used different terminals). Giving users choice - maybe with reasonable defaults, to this I agree - would cover more of those corner cases in my opinion.
Hello,
I'm new to open source and interested in contributing to JabRef.I would like to work on this issue, So please allow me to work on it.
I've a question regarding implementation:
I'm providing an option to set command or program for default file browser, where user can explicitly set command or let JefRef to set deafult behaviour like this:

Now, when user clicks "open folder", JabRef will try to look whether file browser command(in Preference Tab) is explicitly set by the user or not, If yes then it will execute that command otherwise default behaviour will be applied by checking "DESKTOP_SESSION" environment variable.
So Is this solution correct or Do I have to find some other way?
Looks good! Thanks for working on this!
Please also check the case that no desktop season is present and user has not selected any application for opening. In that case it would be nice to print a log message or notification
I've a question regarding implementation:
I'm providing an option to set command or program for default file browser, where user can explicitly set command or let JefRef to set deafult behaviour like this:
I also agree, this looks good! The detail I want to highlight: the "execute command" would make sense for any external program, also the pdf viewer. I mention this because the pdf viewer does not have an "execute command" option in the screenshot - I don't know if that was still WIP when you did the screenshot. And in all of those cases a descriptive error message in case something goes wrong (environment variable missing, etc) would be beneficial. Thanks!
@Siedlerchr and @pirius thanks for your comment.
I'm not able to reproduce this error on my ubuntu 18.04 system, but I hope this will solve this issue(NPE):
@Override
public void openFolderAndSelectFile(Path filePath) throws IOException {
String desktopSession = System.getenv("DESKTOP_SESSION");
String cmd = "xdg-open " + filePath.toAbsolutePath().getParent().toString(); //default command
if(Objects.nonNull(desktopSession)){
desktopSession = desktopSession.toLowerCase(Locale.ROOT);
if (desktopSession.contains("gnome")) {
cmd = "nautilus" + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("kde")) {
cmd = "dolphin --select " + filePath.toString().replace(" ", "\\ ");
}
}
Runtime.getRuntime().exec(cmd);
}
need a comment on this..
And I've one more question:
I'm neither familiar with windows nor have access to windows. So what should be default command for opening file browser?
Is this correct : Runtime.getRuntime().exec("explorer.exe /select," + path);
I need to set this default behaviour in JabRefPreferences.
Thanks to @deepakkumar96 this issue should now be resolved.
We would like to ask you to use a development build from https://builds.jabref.org/master and report back if it works for you. Please remember to make a backup of your library before trying-out this version.
Hello @Siedlerchr,
Sorry for the late reply, I was busy in the past last few weeks,
I've tested fix for both issue #4763(this one) and #4802 under Ubuntu 18.01 with the 'JabRef--master--latest.jar' And It worked for me.
Please let me know if there is any other issue related to this PR.
I can confirm, this successfully solved the issue. Good work!
@deepakkumar96 Both issues are solved thanks to your PR. Thanks again for your contribution.
Thank you @pirius and @Siedlerchr
Most helpful comment
Now, when user clicks "open folder", JabRef will try to look whether file browser command(in Preference Tab) is explicitly set by the user or not, If yes then it will execute that command otherwise default behaviour will be applied by checking "DESKTOP_SESSION" environment variable.
So Is this solution correct or Do I have to find some other way?