Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-764

IOUtils.write() throws OutOfMemoryError/NegativeArraySizeException while writing big strings

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.11.0
    • 2.12.0
    • None
    • None

    Description

      Currently, if I try to write a sufficiently big to a stream, IOUtils.write fails:

      java.lang.NegativeArraySizeException: -1283060862
      at java.base/java.lang.StringCoding.encodeUTF8(StringCoding.java:904)
      at java.base/java.lang.StringCoding.encode(StringCoding.java:449)
      at java.base/java.lang.String.getBytes(String.java:964)
      at org.apache.commons.io.IOUtils.write(IOUtils.java:3251)
      at org.apache.commons.io.FileUtils.writeStringToFile(FileUtils.java:3541)
      at org.apache.commons.io.FileUtils.writeStringToFile(FileUtils.java:3524)

      The reason for this is that getBytes does not support Strings with this size. This should be fixed.

      Attachments

        Activity

          People

            ggregory Gary D. Gregory
            DaGeRe1989 David Georg Reichelt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 50m
                1h 50m