views:

57

answers:

5

I got some weird exception when trying to compile this:

  Byte b = 2;
  if (b < new Integer(5)) {
     ...
  }

Is it a valid check (unboxing-implicit cast - unboxing)?

+1  A: 
public class test
{
public static void main( String[] args )
{
Byte b = 2;
if( b < new Integer(5) )
{
System.out.println( "Working." );
}
}
}

Works for me. (Java 1.6.0_17).

Stefan Kendall
+1  A: 

If you're getting an Internal Compiler Error (ICE), it's a bug in the Java compiler itself, not necessarily anything wrong with your code.

Your code snippet compiles fine on a recent OpenJDK. What Java compiler are you using?

ZoogieZork
A: 

My compiler version used is: 1.6.0_16-b01 for 6.0 compliant It looks like the problem disappears if I switch to 5.0 compliant code.

Robert
Can you compile Stafan Kendall's complete, concise example program?
Tom Hawtin - tackline
From Stefan's response it sounds like it's already been fixed in a newer version (assuming you are both using the "normal" Sun javac). If you're not using Sun's javac then I'd definitely follow Tom Hawtin's advice to get bug noticed by the vendor.
ZoogieZork
The given example works fine.
Robert
So it's a problem outside of the code you have quoted. Can you construct a simple example that fails?
Tom Hawtin - tackline
Robert
+2  A: 

If there is a bug in your compiler, here's what you do:

  • Make sure you are using an up to date version of the compiler.
  • If the vendor has a public bug database, check that (hint: use actual text copy-and-pasted from the exception trace).
  • If it's a known bug, up vote it, raise an escalation, whatever.
  • If you can't find a copy of the bug, submit a bug report with a concise, compilable (or not!) test case.

In general, it's not useful to post about random bugs in software products on Q&A sites.

Tom Hawtin - tackline
ok, I thought that the problem is the code. thanks
Robert
If the compiler throws an exception, it is a bug in the compiler!
Tom Hawtin - tackline
A: 

As an aside, consider using Integer.valueOf(5) in place of new Integer(5); the former is generally more efficient.

trashgod