Note that there are some explanatory texts on larger screens.

plurals
  1. POJava StringIndexOutOfBounds Exception in Server 2008 r2 environment
    primarykey
    data
    text
    <p>Here is a very simple chunk of code using a jre 1.6 run time environment and running in a 64 bit server Server 2008 R2: .... </p> <pre><code> cntr = 0; while (cntr &lt; localheaders.size()) { String tempText = textstring.toUpperCase(); int pos = 0; int lastindx = 0; int lendPos; int tendPos = 0; while ((pos &gt; -1) &amp;&amp; (tempText.length() &gt; 0)) { int headerLengthbeforeUpper = localheaders.get(cntr).header.length(); String aHeader = localheaders.get(cntr).header.toUpperCase(); int headerLengthafterUpper = aHeader.length(); pos = tempText.indexOf(aHeader); // 10_21_2010 if (pos &gt; 0) { // ef 07-10-2011 char c; try { c = tempText.charAt(pos - 1); if (Character.isLetterOrDigit(c)) pos = -1; } catch (Exception e) { System.out.println("Value of pos-&gt;" + pos); System.out.println("Length of the string-&gt;" + tempText.length()); System.out.println("header length before-&gt;"+headerLengthbeforeUpper); System.out.println("header length after-&gt;"+headerLengthafterUpper); e.printStackTrace(); } } ........ </code></pre> <p>What I am finding is that the statement <code>pos = tempText.toUpperCase().indexOf(aHeader);</code> (about 10 lines down) is being set intermittently to a value in the string <code>tempText</code> that is greater than the length of the string. This results in a <code>java.lang.StringIndexOutOfBoundsException</code>. The index is always within 100 of the actual length of the string. For example, in a test I ran this evening, the <code>pos</code> varaible was set to 24432 for a string of length 24404. Header length is the same before and after uppercasing to address one of the comments below. Note, if I re-run the code on the same file twice in a row, the error does not occur, the second time. </p> <p>Some additional information:</p> <ol> <li>I don't believe its a threading issue since there is only one thread being used.</li> <li>The code runs fine in a 32 bit XP environment. </li> <li>Both pos and tempText are locally defined variables. </li> <li>When I type java -version, I see the following:</li> </ol> <blockquote> <p>Java version "1.6.0_20" Jav(TM) SE Runtime Environment (build 1.6.0_20-b02) Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)</p> </blockquote> <p>The test environment is running in a VMware Workstation. </p> <p>I believe this is an environment issue, give the strangeness of the error and the fact that it only shows up in my 64 bit test environment. I'm trying to figure out the source of the problem. Has anyone, had this kind of error in the past? Is anyone aware of bugs related to this particular java build that might cause this kind of error?</p> <p>Any ideas on how to trouble shoot this problem?</p> <p>Thank you,</p> <p>Elliott</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload