JDK-6558572 : javac accepts semantically invalid == test
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2007-05-17
  • Updated: 2010-04-02
  • Resolved: 2007-05-17
Related Reports
Duplicate :  
Description
boolean b = ((Object)null == 3);
   should not compile since it's not a numerical equality test
   (JLS15.21.1) nor a boolean equality test (15.21.2) nor a
   reference equality test (15.21.3). Indeed, it does not compile.

boolean b = (3 == (Object)null);
   should not compile for exactly the same reason, but does compile!
   I am told javac performs a boxing conversion followed by a
   widening reference conversion, which isn't a valid combination
   allowed under casting conversion (mentioned in 15.21.3), so I am
   not sure what javac is trying to do.