Saturday, April 14, 2012

Java wat

I'm sure quite a few you have seen the "wat" talk exposing some funny behaviors of Ruby and JavaScript. Working in the industrial/enterprise/boring Java language most of the time for Native Fennec's development, we've been missing out on such interesting moments. Nevertheless, I present you this gem, from bug 745384:
  • (null instanceof <anything>)  = false
    This is guaranteed by the language spec:
     "At run time, the result of the instanceof operator is true if the value of the RelationalExpression is not null and the reference could be cast (§15.16) to the ReferenceType without raising a ClassCastException. Otherwise the result is false."
  • IsInstaceOf(NULL, <anything>) = JNI_TRUE
    This too is guaranteed by the language spec:
     "Returns JNI_TRUE if obj can be cast to clazz; otherwise, returns JNI_FALSE. A NULL object can be cast to any class."
I don't know what the people at Sun were thinking when they designed it this way, but right now I'm all:


For those wondering, these are the relevant Java bugs:
Note the "Closed, Not a Defect, Fixed in spec." It's not a bug, it's a feature, :-)