title: Working around Java JIT bug
body: <p>We seem to be subject to a strange bug in our Java environment.
  We've now had two occurrences of the same "can't happen" exception; in one case the problem occurred 42,551 times over a period of 48 minutes in a running process and then spontaneously cleared itself.</p>
  
  <p>The failing code is triggered by this line:</p>
  
  <pre><code>return String.format("%1d%XY%d", source, System.currentTimeMillis(), quoteID);
  </code></pre>
  
  <p>where <code>int source = 0</code> and <code>long quoteID = 44386874</code> (for example).</p>
  
  <p>The exception is:</p>
  
  <pre><code>java.util.UnknownFormatConversionException: Conversion = 'd'
          at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2605)
          at java.util.Formatter$FormatSpecifier.&lt;init&gt;(Formatter.java:2633)
          at java.util.Formatter.parse(Formatter.java:2479)
          at java.util.Formatter.format(Formatter.java:2413)
          at java.util.Formatter.format(Formatter.java:2366)
          at java.lang.String.format(String.java:2770)
  </code></pre>
  
  <p>Checking the code <code>'d'</code> should never raise this exception.</p>
  
  <p>The best explanation we've come up with is that the JIT compiler is generating bad bytecode, but on a subsequent re-JIT it writes good code.</p>
  
  <p>Anyone have any experience of ways to work around / diagnose such a problem?</p>
  
  <p>Roger.</p>