Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » "for" loop error (?) - terminates early
"for" loop error (?) - terminates early [message #754924] Sat, 05 November 2011 04:58 Go to next message
S  is currently offline S Friend
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:
2147483646
2147483647

to the console, but it doesn't. Instead, the first value seems to be selected at random; for example, I get stuff like:
388322
2147483647

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 #755697 is a reply to message #754924] Wed, 09 November 2011 10:40 Go to previous messageGo to next message
Luca Ferrari is currently offline Luca FerrariFriend
Messages: 159
Registered: November 2009
Senior Member
I confirm the error, using Eclipse 3.6.2 on Ubuntu Linux with JDK 1.6. The same application compiled and runned directly from the command line works as expected. Even changing the compiler settings within Eclipse does not seem to solve the problem.
Re: "for" loop error (?) - terminates early [message #755716 is a reply to message #755697] Wed, 09 November 2011 11:29 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
I tried Eclipse 3.6.2 on Windows with Sun/Oracle JDK 1.6.0_23 and it works fine. Is there any compiler preference modified?
Re: "for" loop error (?) - terminates early [message #756419 is a reply to message #754924] Sun, 13 November 2011 01:15 Go to previous messageGo to next message
S  is currently offline S Friend
Messages: 3
Registered: November 2011
Junior Member
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.
Re: &quot;for&quot; loop error (?) - terminates early [message #756437 is a reply to message #756419] Sun, 13 November 2011 10:44 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
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 #757325 is a reply to message #756437] Thu, 17 November 2011 17:51 Go to previous messageGo to next message
S  is currently offline S Friend
Messages: 3
Registered: November 2011
Junior Member
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.
Re: &quot;for&quot; loop error (?) - terminates early [message #757673 is a reply to message #757325] Mon, 21 November 2011 08:51 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
This works fine on Windows but fails on Linux. This passes if JIT is turned off(-Xint). As Deepak had mentioned this should be a bug with JIT. Look at https://bugs.eclipse.org/bugs/show_bug.cgi?id=353836 for more details.
Re: &amp;quot;for&amp;quot; loop error (?) - terminates early [message #757855 is a reply to message #757325] Fri, 18 November 2011 17:55 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
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
Re: &amp;quot;for&amp;quot; loop error (?) - terminates early [message #758142 is a reply to message #757673] Tue, 22 November 2011 05:07 Go to previous message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
I do see the problem with the class file on Linux.
Previous Topic:ASTRewrite to add new Method after comment
Next Topic:Having problem setting up web services in Eclipse Helios
Goto Forum:
  


Current Time: Thu Sep 26 06:27:06 GMT 2024

Powered by FUDForum. Page generated in 0.07339 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top