I'm getting an error while concatenating a null string to a string with some values : <p>For one of the following snippet I'm getting a run-time exception.</p>

<pre><code>public class Demo {

   public static void main(String[] args) {
          String org="This is the new shit.This is the new.";
          String search="is";
          String sub="was";
          int i;
          String result="";
          do{
                 i=org.indexOf(search);
                 if(i==-1)
                       break;
                 result=result+org.substring(0,i);
                 result=result+sub;
                 result=result+org.substring(i+search.length());
                 org=result;
          }while(i!=-1);
          System.out.println(org);
   }
</code></pre>

<p>}</p>

<p>The exception thrown is as follows:</p>

<pre><code>at java.util.Arrays.copyOfRange(Unknown Source)
   at java.lang.String.&lt;init&gt;(Unknown Source)
   at java.lang.StringBuilder.toString(Unknown Source)
   at strings.Demo.main(Demo.java:16)
</code></pre>

<p>Can anyone tell why this exception is being thrown.</p>
