What's really strange about this code is that when you call discoverParadox() for the third time, with the same input, it produces a different result... Really strange. I don't see how that happens.
Jesper Young wrote:What's really strange about this code is that when you call discoverParadox() for the third time, with the same input, it produces a different result... Really strange. I don't see how that happens.
Me neither! The more I investigate the more strange it becomes. Changing the method name does not change anything. Setting a variable to Integer.MIN_VALUE and using that gives the same output. Setting a value to -2147483648 and using that as the argument does not change anything.
Bizarre !
Apparently it's a Hotspot bug and running with -Xint makes it run as expected.
C:\Users\wouter\Desktop\Temp>java Huh
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
C:\Users\wouter\Desktop\Temp>java -Xint Huh
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet wrote:It returns the same results using -Xint:
C:\Users\wouter\Desktop\Temp>java Huh
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
Wouter, what version of Java are you using on what operating system?
I'm using JDK 1.6.0 update 22 (64-bit) on 64-bit Windows Server 2008 R2 and I'm getting the same output as Bruce showed in his opening post.
Kurt Van Etten
Ranch Hand
Joined: Sep 07, 2010
Posts: 98
posted
0
For whatever it's worth, I'm getting normal behavior (under Windows XP):
C:\Documents and Settings\Kurt Van Etten\Desktop\Java>javac Huh.java
C:\Documents and Settings\Kurt Van Etten\Desktop\Java>java Huh
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
C:\Documents and Settings\Kurt Van Etten\Desktop\Java>java -version
java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) Client VM (build 17.1-b03, mixed mode, sharing)
I find it somewhat alarming that other people are getting the weird behavior, though. That seems like a potentially serious bug in the VM.
Jesper Young wrote:Wouter, what version of Java are you using on what operating system?
I'm using JDK 1.6.0 update 22 (64-bit) on 64-bit Windows Server 2008 R2 and I'm getting the same output as Bruce showed in his opening post.
I'm using:
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
Windows 7 Home Premium 64bit
But I'm getting the same results with:
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b112)
Java HotSpot(TM) Client VM (build 20.0-b01, mixed mode, sharing)
Kurt Van Etten
Ranch Hand
Joined: Sep 07, 2010
Posts: 98
posted
0
Here's a question for the people who are getting the strange behavior: if you change the for loop in the main method to iterate 4 times instead of 3, do you get something like the output below?
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: false, life: 2
life < 0: false, life: 28
life < 0: false, life: 54
Bobby Smallman
Ranch Hand
Joined: Sep 09, 2010
Posts: 107
posted
0
Kurt Van Etten wrote:Here's a question for the people who are getting the strange behavior: if you change the for loop in the main method to iterate 4 times instead of 3, do you get something like the output below?
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: false, life: 2
life < 0: false, life: 28
life < 0: false, life: 54
No, after the third time, it consistently will print -24, 2, 28 for every additional attempt.
Also, I find it interesting that in Eclipse I will get the problem everytime if I run the program normally or in debug mode WITHOUT break points. However, if I run the program with a break point just inside the if(life > 50) statement and step through the program I will not get the extra 2 and 28 lines of output.
Another interesting aspect is that if you change line 23 to it will also prevent the extra 2 and 28 lines.
Hauke Ingmar Schmidt
Rancher
Joined: Nov 18, 2008
Posts: 371
posted
0
Bruce Coleman wrote:I'm just going to be a manager. Somebody, please take my keyboard.
Er.... what?
Bruce Coleman
Greenhorn
Joined: Mar 28, 2002
Posts: 9
posted
0
Thank you for the confirmations. I'll log a bug with Sun --ack! ...with Oracle.
H:\Java>java Huh
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
H:\Java>java -Xint Huh
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
H:\Java>java -version
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) Client VM (build 14.1-b02, mixed mode, sharing)
Windows XP Professional, version 5.1
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
4
posted
0
The title of your thread reads rather like . . . which I keep telling my undergraduates, always evaluates to true. So it isn't a paradox. If (false == true) then the universe will end today with a return value of 42, but it tells you nothing about what happens if (false ≠ true); in that case anything may happen. Not a paradox at all.
And will that code compile? Surely end(int) is an instance method of the Universe class
Bruce Coleman
Greenhorn
Joined: Mar 28, 2002
Posts: 9
posted
0
A brief update, were anybody curious:
This issue still exists with the latest JRE for Windows 7 x64. Sun --pft! ...O-r-a-c-l-e (emailing from sun.com) only responded with an automated email that they'd look into the issue, and if they agreed the problem existed, then they'd identify an existing bug that covered the problem or file a new bug and send me an update. I've since received no update from them. So, I'll log the issue, again.
Henry Wong wrote:
BTW, like Marc, I am using the client JIT compiler -- while you seem to be using the server JIT compiler. Maybe that's the difference?
Henry Wong wrote:
BTW, like Marc, I am using the client JIT compiler -- while you seem to be using the server JIT compiler. Maybe that's the difference?
BINGO !! Switched over to the server JIT compiler and got the error.
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\> java Huh
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
C:\> java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)
C:\> java -server Huh
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: true, life: -24
life < 0: false, life: 2
life < 0: false, life: 28