Java Crash while downloading File

Luis :

I want do download a big .jar file from my own Server. (https://luis.team) There for I made a thread to download it, because it is very huge. Here is my code for download:

public Update(String version, File outputFile) {

    URL url;
    URLConnection connection = null;
    try {
        url = new URL("https://raw.githubusercontent.com/Luuuuuis/InstantVerify/master/version");
        connection = url.openConnection();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    assert connection != null;
    try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
        String[] versionCode = in.readLine().split("&&");

        if (!(versionCode[0].equalsIgnoreCase(version))) {

            /*
             * Download from URL given in version file
             */

            if(versionCode[1] != null && !versionCode[1].equalsIgnoreCase("null")) {

                Thread th = new Thread(() -> {

                    try {

                        URL downloadURL = new URL(versionCode[1]);

                        URLConnection urlConnection = downloadURL.openConnection();
                        urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");

                        InputStream inputStream = urlConnection.getInputStream();
                        OutputStream outputStream = new FileOutputStream(outputFile);

                        byte[] buffer = new byte[1024];

                        int length;
                        while ((length = inputStream.read(buffer)) != -1) {
                            outputStream.write(buffer, 0, length);
                        }

                        inputStream.close();
                        outputStream.close();

                        InstantVerify.version += " (outdated)";


                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                });
                th.start();

            }
        } else {
            InstantVerify.version += " (latest)";
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

After this I get a very little file(around 30MB) and an Java Runtime Error:

A fatal error has been detected by the Java Runtime Environment:

SIGBUS (0x7) at pc=0x00007f8fd9b5ed10, pid=14021, tid=0x00007f8fa5b56700

JRE version: Java(TM) SE Runtime Environment (8.0_201-b09) (build 1.8.0_201- 
b09)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode linux- 
amd64 compressed oops)
Problematic frame:
C  [libzip.so+0x11d10]  newEntry.isra.4+0x60

Failed to write core dump. Core dumps have been disabled. To enable core 
dumping, try "ulimit -c unlimited" before starting Java again

An error report file with more information is saved as:
/home/ServerTest/Bungee/hs_err_pid14021.log
Compiled method (nm)    6767  201     n 0       
java.util.zip.ZipFile::getEntry (native)
total in heap  [0x00007f8fc517a510,0x00007f8fc517a868] = 856
relocation     [0x00007f8fc517a638,0x00007f8fc517a678] = 64
main code      [0x00007f8fc517a680,0x00007f8fc517a868] = 488

If you would like to submit a bug report, please visit:
http://bugreport.java.com/bugreport/crash.jsp
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.
Aborted

I guess there is a issue with Memory Mapping in Java, because my root Server has only 2GB of RAM. What can I do do fix this? Thank you.

Luis :

I fixed this issue with a workaround.

URL downloadURL = new URL(versionCode[1]);
HttpURLConnection urlConnection = (HttpURLConnection) downloadURL.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
InputStream inputStream = urlConnection.getInputStream();
Files.copy(inputStream, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
inputStream.close();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=147766&siteId=1