aspose file tools*
The moose likes Beginning Java and the fly likes if (false == true) Universe.end(42); Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "if (false == true) Universe.end(42);" Watch "if (false == true) Universe.end(42);" New topic
Author

if (false == true) Universe.end(42);

Bruce Coleman
Greenhorn

Joined: Mar 28, 2002
Posts: 9
It's late where I am, and I have a headache.

Output:
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
Bruce Coleman
Greenhorn

Joined: Mar 28, 2002
Posts: 9
I'm just going to be a manager. Somebody, please take my keyboard.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

So what is the problem? How does the output differ from your expectation?


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Bobby Smallman
Ranch Hand

Joined: Sep 09, 2010
Posts: 107
While I appreciate the slight Hitchhiker's Guide to the Galaxy reference, I have no idea what types of responses you are looking for with this.


Everyday in every way, we get a little better.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14433
    
  23

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

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.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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

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.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

I don't see any strange behavior here, it (JDK 1.6.0_07) returns the same results with/without -Xint.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14433
    
  23

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
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.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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
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
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: 433
    
    2
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
Thank you for the confirmations. I'll log a bug with Sun --ack! ...with Oracle.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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: 40052
    
  28
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
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.

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I've since received no update from them.

Things aren't free anymore partner


[My Blog]
All roads lead to JavaRanch
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

marc weber wrote:H:\Java>java 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


This works for me too... using Java 1.6.0_17-b04. Windows 7, 64 bit.

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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?

Good point.

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

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



[EDIT: beaten by less than a minute]

Henry
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Could it be related to this bug ?

Henry Wong wrote:[EDIT: beaten by less than a minute]Henry

RedDead Redemption made me a fast shooter.
Jim Newton
Greenhorn

Joined: Feb 22, 2011
Posts: 11
I don't get the strange behavior

Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)

under 32-bit Ubuntu 10.04

--------------------
... but running with -server option I do

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: if (false == true) Universe.end(42);