Library does not initialise on Linux
vgaj opened this issue · comments
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.
@vgaj use 1.8.2
*-alpha.*
is broken
2.0.0-alpha.6 have null point exception prablem to linux
you neet set systemevn SystemRoot = "some empty path"