commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ingimar (Jira)" <>
Subject [jira] [Created] (CODEC-265) java.lang.NegativeArraySizeException
Date Tue, 05 Nov 2019 16:12:00 GMT
Ingimar created CODEC-265:

             Summary:   java.lang.NegativeArraySizeException
                 Key: CODEC-265
             Project: Commons Codec
          Issue Type: Bug
    Affects Versions: 1.13
         Environment: Linux = Ubuntu 18.04.3 LTS

JDK = 1.8

            Reporter: Ingimar
         Attachments:,, pom.xml


trying to encode a file that is 1GB of size.

( linux :
fallocate -l 1GB{code}

I want to post that file to a RESTful-service, package in JSON.

*here is the code* 


String filePath = "/tmp/";
System.out.println("\t Post to  : ".concat(URL));
 System.out.println("\t file : ".concat(filePath));
Path path = Paths.get(filePath);
 byte[] bArray = Files.readAllBytes(path);
// testing commons codec 1.16 (2019-11-05)
 byte[] encodeBase64 = Base64.encodeBase64(bArray);
final String contentToBeSaved = new String(encodeBase64);
HttpClient client = HttpClientBuilder.create().build();
 HttpResponse response = null;
JSONObject metadata = new JSONObject();
 metadata.put("owner", "Ingo");
 metadata.put("access", "public");
 metadata.put("licenseType", "CC BY");
 metadata.put("fileName", "fileName");
 metadata.put("fileDataBase64", contentToBeSaved);
String metadataFormatted = StringEscapeUtils.unescapeJavaScript(metadata.toString());
StringEntity entity = new StringEntity(metadataFormatted, ContentType.APPLICATION_JSON);
HttpPost post = new HttpPost(URL);
 response = client.execute(post);
 HttpEntity responseEntity = response.getEntity();
String responseFromMediaserver = EntityUtils.toString(responseEntity, "UTF-8");
 System.out.println("Response is : " + responseFromMediaserver);
JSONObject json = new JSONObject(responseFromMediaserver);
 String uuid = json.getString("uuid");
 System.out.println("UUID is " + uuid);

 # mvn clean package
 #   java -Xms512m -Xmx20480m -jar target/mediaClient.jar 

The crasch is in

byte[] encodeBase64 = Base64.encodeBase64(bArray);{code}

the stacktrace is :
Starting NewClientEncodePost
 Post to :
 file : /tmp/
Exception in thread "main" java.lang.NegativeArraySizeException
 at org.apache.commons.codec.binary.BaseNCodec.resizeBuffer(
 at org.apache.commons.codec.binary.BaseNCodec.ensureBufferSize(
 at org.apache.commons.codec.binary.Base64.encode(
 at org.apache.commons.codec.binary.BaseNCodec.encode(
 at org.apache.commons.codec.binary.BaseNCodec.encode(
 at org.apache.commons.codec.binary.Base64.encodeBase64(
 at org.apache.commons.codec.binary.Base64.encodeBase64(
 at org.apache.commons.codec.binary.Base64.encodeBase64(
 at org.apache.commons.codec.binary.Base64.encodeBase64(


This message was sent by Atlassian Jira

View raw message