[
https://issues.apache.org/jira/browse/IO-764?focusedWorklogId=752177&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-752177
]
ASF GitHub Bot logged work on IO-764:
-------------------------------------
Author: ASF GitHub Bot
Created on: 04/Apr/22 10:15
Start Date: 04/Apr/22 10:15
Worklog Time Spent: 10m
Work Description: DaGeRe opened a new pull request, #343:
URL: https://github.com/apache/commons-io/pull/343
If Strings with a certain size are written to a stream, this fails with an
exception on OpenJDK 11.
```
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)
```
This PR fixes the problem by using a `ByteBuffer` instead `getBytes`.
Unfortunately, this increases test time significantly. One workaround would
be to disable the test and only enable it if needed - but testing whether big
Strings can be written is not possible without handling such a big string.
Issue Time Tracking
-------------------
Worklog Id: (was: 752177)
Remaining Estimate: 0h
Time Spent: 10m
> Unable to Write Big Strings Using IOUtils
> -----------------------------------------
>
> Key: IO-764
> URL: https://issues.apache.org/jira/browse/IO-764
> Project: Commons IO
> Issue Type: Bug
> Affects Versions: 2.11.0
> Reporter: David Georg Reichelt
> Priority: Critical
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Currently, if I try to write a sufficiently big to a stream, IOUtils.write
> fails:
> {code:java}
> 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){code}
> The reason for this is that getBytes does not support Strings with this size.
> This should be fixed.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)