Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library does not initialise on Linux #308

Open
vgaj opened this issue Aug 26, 2023 · 2 comments
Open

Library does not initialise on Linux #308

vgaj opened this issue Aug 26, 2023 · 2 comments

Comments

@vgaj
Copy link

vgaj commented Aug 26, 2023

When using the library on Linux it fails to start up with the following exception:
Caused by: java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:209)
at java.base/sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:263)
at java.base/java.nio.file.Path.of(Path.java:147)
at java.base/java.nio.file.Paths.get(Paths.java:69)
at org.pcap4j.core.NativeMappings.(NativeMappings.java:46)

I was using the library via Maven dependency

org.pcap4j
pcap4j-core
2.0.0-alpha.6

Looking at the code we can see that it's trying to use an environment variable called "SystemRoot" which won't exist when running on Linux.
static final File NPCAP_DIR =
Paths.get(System.getenv("SystemRoot"), "System32", "Npcap").toFile();

To work around the problem all you need to do is to define the environment variable before starting the application using the library. So there is an easy work around.
export SystemRoot=""

However updating the code with a Platform.isWindows() check will avoid having to do this.

@freedom1b2830
Copy link

@vgaj use 1.8.2
*-alpha.* is broken

@asdf101221
Copy link

2.0.0-alpha.6 have null point exception prablem to linux
you neet set systemevn SystemRoot = "some empty path"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants