While I was working on my download manager yesterday I found a bug in java. Every time I tried to make a connection to a fedora iso file I would get this error:
java.lang.NumberFormatException: For input string: "3580680192" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:459) at java.lang.Integer.parseInt(Integer.java:497) at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:398) at sun.net.www.URLConnection.getContentLength(URLConnection.java:185) at mercier.lib.download.FTPDownloadConnectionFactory.initDownloadFromConnection(FTPDownloadConnectionFactory.java:50) at mercier.lib.download.FTPDownloadConnectionFactory.getVerifiedConnection(FTPDownloadConnectionFactory.java:71) at mercier.lib.download.FTPDownloadConnectionFactory.getConnection(FTPDownloadConnectionFactory.java:88) at mercier.lib.download.ConnectionFactory.getConnection(ConnectionFactory.java:60) at mercier.lib.download.ConnectionFactoryTest.testGetFTPDownloadConnection(ConnectionFactoryTest.java:119) at ...
Does anyone know why this would happen? I found out after looking it up and finding bug #5052093. It happened because the api for contentLength uses an int return value, which has a max of 2,147,483,647. Not only that but when the internal code parses the contentLength from the stream it has to parseInt in order to return an int. Since anything above 2,147,483,647 is not an int a NumberFormatException is thrown. The content-length for the iso is 3,580,680,192.
The fix for this bug is only in JDK7 which can only be downloaded as a snapshot from java.net. Since they couldn’t change the original getContenthLength a new getContethLengthLong method has been added. From now on I’m going to use JDK7 even though it’s not out yet.