title: "Can't overwrite cause" when setting a cause on exception with a null cause
body: <p>I have a <code>RuntimeException</code> that has no cause (<code>t.getCause() returns null</code>). When my code runs <code>t.initCause(exceptionToAttach)</code>, it gives me an <code>IllegalStateException</code> with the message "Can't overwrite cause". </p>
  
  <p>I wouldn't have thought this was possible. The exceptionToAttach is simply a new <code>RuntimeException()</code>, which seems to have itself set as the cause for some reason.</p>
  
  <p>Any ideas what's going on?</p>
  
  <p><strong>edit with some relevant code</strong></p>
  
  <pre><code>public static void addCause(Throwable e, Throwable exceptionToAttach) {
      // eff it, java won't let me do this right - causes will appear backwards sometimes (ie the rethrow will look like it came before the cause) 
      Throwable c = e;
      while(true) {
          if(c.getCause() == null) {
              break;
          }
          //else
          c = c.getCause();        // get cause here will most likely return null : ( - which means I can't do what I wanted to do
      }
  
      c.initCause(exceptionToAttach);
  }
  </code></pre>