Bug: 'Boolean.TRUE.booleanValue()' does not evaluate to true.

28 views
Skip to first unread message

Udo

unread,
Oct 30, 2012, 11:27:28 AM10/30/12
to java2...@googlegroups.com
It looks like there is a bug in the implementation of Boolean.booleanValue().

Running the following program prints out "b is true" when executed in Java, but "b is NOT true" when running through J2S:


public class Foo {
public static void main(String[] args) {
Boolean o = Boolean.TRUE;
boolean b = o.booleanValue(); 
// b should now be true.
if (b) {
System.out.println("b is true");
} else {
System.out.println("b is NOT true");
System.out.println("b = "+b);
System.out.println("o = "+o);
}
}
}


The complete output in the error case is:

b is NOT true
b = undefined
o = true


Udo

Zhou Renjian

unread,
Oct 30, 2012, 9:43:35 PM10/30/12
to java2...@googlegroups.com

Try to replace j2slib in net.sf.j2s.lib with http://dev.zhourenjian.com/j2s/j2slib.v20120912.zip before new release is available.

--
You received this message because you are subscribed to the Google Groups "Java2Script" group.
To post to this group, send email to java2...@googlegroups.com.
To unsubscribe from this group, send email to java2script...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/java2script/-/Cir5OUO5oooJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Udo

unread,
Oct 31, 2012, 5:38:07 AM10/31/12
to java2...@googlegroups.com
Thanks for the fast response.

That fixes the bug I reported.

However... ;)

I had a look at your changes. It looks like you replaced "this.value" by "this.valueOf()" to access the "hidden" variable 'value' in the constructor's closure.

Shouldn't Boolean.compareTo also call "b.valueOf()" instead of "b.value"?

return (b.valueOf() == this.valueOf () ? 0 : (this.valueOf () ? 1 : -1));
 

Nevertheless, thanks again,

Udo
Reply all
Reply to author
Forward
0 new messages