"for" loop error (?) - terminates early [message #754924] |
Sat, 05 November 2011 04:58 |
S Messages: 3 Registered: November 2011 |
Junior Member |
|
|
Hello everyone,
I seem to have encountered a really strange issue. Consider the following code:
public class Main {
public static void main(String[] args) {
int a = 0;
for (int i = 0; i < Integer.MAX_VALUE; i++) {
a = i;
}
System.out.println(a);
System.out.println(Integer.MAX_VALUE);
}
}
Now, I'd expect this to print:
to the console, but it doesn't. Instead, the first value seems to be selected at random; for example, I get stuff like:
So far, I've only been able to get errors like that to appear with the code above. If, for example, I change the loop to "for (int i = 0; i < Integer.MAX_VALUE - 1; i++)" or add something else to the loop body, the result is correct.
I'm using Eclipse Indigo (20110916-0149) and OpenJDK 1.6.0_22 with Linux Mint 11, but as far as I can tell, I seem to have the same issue with the Sun/Oracle JDK 1.6.0_26.
Am I going insane or is this some kind of weird compiler optimization bug?
|
|
|
|
|
|
Re: "for" loop error (?) - terminates early [message #756437 is a reply to message #756419] |
Sun, 13 November 2011 10:44 |
Deepak Azad Messages: 543 Registered: July 2009 |
Senior Member |
|
|
On 11/13/2011 6:45 AM, SimonMay1993 wrote:
> As far as I know, I haven't modified any compiler preferences. I created
> a completely new project in Eclipse to test this.
>
> Also, I've tried compiling the same file with javac instead of Eclipse,
> and that seems to be working correctly. The two generated .class files
> are very different, actually, but I don't know a lot about the .class
> file format, so I can't tell where the problem could be. I could upload
> the two different files, though.
Sure, you can post the class files. (Though I don't see how the
generated class file could be wrong)
This should be a JIT bug e.g. see
http://comments.gmane.org/gmane.comp.java.openjdk.hotspot.devel/4581
|
|
|
|
|
Re: &quot;for&quot; loop error (?) - terminates early [message #757855 is a reply to message #757325] |
Fri, 18 November 2011 17:55 |
Deepak Azad Messages: 543 Registered: July 2009 |
Senior Member |
|
|
On 11/17/2011 11:21 PM, S wrote:
> Deepak Azad wrote on Sun, 13 November 2011 11:44
>> Sure, you can post the class files. (Though I don't see how the
>> generated class file could be wrong)
>>
>> This should be a JIT bug e.g. see
>
> Well, I got the idea that the .class files generated by Eclipse could be wrong because it was obviously working with javac's .class files. Then again, it might just be that JIT handles Eclipse's .class files incorrectly, so you're probably right. Either way, I've also included the files just in case.
I do not see a problem with the class file. Satyam, do you?
Simon, you may want to report this bug to your JRE provider.
--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
|
|
|
|
Powered by
FUDForum. Page generated in 0.07339 seconds