System.out.print and String.length > ~64K bug?

I have ran into a problem where if a String length is around 63-64K in size the System.out.println method will not print the value of the string. Has anybody else experience this This is code I used to reproduce it.

int indent = 70000;
int k = 0;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < indent; i += 1)
{
sb.append("a");
if (sb.length() >= 53200+k)
{
System.out.print(sb.length()+" \n");
System.out.println(sb);
k+=1000;
}
}



Answer this question

System.out.print and String.length > ~64K bug?

  • Ismail Pazarbasi

    That’s right I’ve over looked at the output. We are looking into this issue and will get back to you with the updates soon.

    Thanks for using J# and reporting this.

    Neela



  • StephenR

    Yes I am using VS 2005. You might be mis-reading the output. It starts off working and then builds the string array large enough to where it stops printing. If you change the 'if (sb.length() >= 53200+k)' to 63000 or so, it will never print anything to the console.

    Doing the following I found if I changed it to use System.Console the following worked fine but System.out will never write anything to the screen:

    int indent = 70000;
    int k = 0;
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < indent; i += 1)
    {
    sb.append("a");
    if (sb.length() >= 63000+k)
    {
    System.out.print(sb.length()+" \n");
    System.out.println("++++++++++++++++out"+sb);
    //System.Console.WriteLine("**********console"+sb);
    k+=1000;
    }
    }



  • Kevin Yockey

    Which version of J# Redist are you using Above code prints the buffer perfectly on VS 2005.

    Neela



  • System.out.print and String.length > ~64K bug?