javacrashjpcap

JpcapWriter causes app to crash


I am working on a relatively simple packet capture application, and I am using the Jpcap library. Everything has been working until I added in the save feature to my program.

My write function

public void write() {
    try {
        writer = JpcapWriter.openDumpFile(captor, fileName);
    } catch (IOException e) {e.printStackTrace();}
    for (Packet packet : this.packets) {
        writer.writePacket(packet);
    }
    writer.close();
}

It correctly gets the captor and filepath, loops through all the packets successfully, but when it tries to write at the end of the code block, the JVM crashes.

My question is, why does my application crash when trying to close the JpcapWriter?

UPDATE: The weird thing I just discovered, is it IS actually writing to the file. It just crashes after the write. I added a print statement after the close, and it never reaches it.


Solution

  • I found several other people with the same issue as me. I'm not sure why but removing the call to close the writer fixed my problem. The file now writes correctly, and has no issues. For now, I am content with it working, but I may come back to this issue at a later date.

    UPDATE: It turns out the the file closes when a call is made to stop the capture. When the capture thread is closed it closes the captor, which in turn closes the writer for me. It essence, I was trying to tell it to close the writer, as the writer was already closing, which caused the JVM to crash.