Maheshjayachandran / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

goog.object.get fails for null object #505

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

What steps will reproduce the problem?
1. goog.object.get(null, 'somekey', 'defaultvalue')

What is the expected output? What do you see instead?
Expected output: 'defaultvalue'
Instead I get: "TypeError: Cannot use 'in' operator to search for 'streams' in 
null"

What version of the product are you using? On what operating system?
Not sure what version, on Chrome M23 beta

Please provide any additional information below.
The type signature of goog.object.get allows null inputs, as clearly indicated 
on http://closure-library.googlecode.com/svn/docs/namespace_goog_object.html .  
If null is not supported then the type signature should be "!Object".  I think 
improving the behavior for null objects would be trivial, and preferable to 
restricting the type signature.

Original issue reported on code.google.com by bem...@google.com on 11 Oct 2012 at 5:02

GoogleCodeExporter commented 9 years ago
Unfortunately the type annotation can't be updated without updating hundreds of 
projects which call goog.object.get with {Object} parameter instead of 
{!Object}.

Accepting null in the first argument would make goog.object.get's behavior 
inconsistent with the rest of the functions in that file.

Original comment by pall...@google.com on 19 Oct 2012 at 8:27

GoogleCodeExporter commented 9 years ago
Then IMHO the logical solution is to fix the behavior of all these
functions to consistently match their type specification.

Original comment by bem...@google.com on 19 Oct 2012 at 3:55

GoogleCodeExporter commented 9 years ago
This is this way due to historical reason. goog.object was never meant to 
accept non-null parameter. In the past, the compiler default was that the 
annotation Object means non-null. This was changed (probably prior to open 
sourcing) to mean Object|null. However, fixing this kind of annotation issues 
is hard (and goog.object is not the only one affected unfortunately). Adding 
null checks are not usually desirable due to the additional bytes sent to 
client. Though adding goog.asserts.assert may be a reasonable alternative.

Original comment by chrishe...@google.com on 19 Oct 2012 at 7:37