[SERVER-11156] Useless code in shell save() function Created: 12/Oct/13  Updated: 07/Apr/23  Resolved: 18/Oct/13

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.4.6
Fix Version/s: 2.5.4

Type: Bug Priority: Minor - P4
Reporter: Frédéric G. MARAND Assignee: Unassigned
Resolution: Done Votes: 0
Labels: neweng, pull-request
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux


Backwards Compatibility: Fully Compatible
Operating System: Linux
Steps To Reproduce:

launch shell
type db.foo.save
look at source

Participants:

 Description   

save() starts by this:

if ( obj == null || typeof( obj ) == "undefined" )
throw "can't save a null";

This is apparently to catch both null and undefined.

However, since the first check only uses == instead of ===, it matches undefined, and the second part of the check is never used. This could be improved in one of two ways:

  • drop the second part of the check since it is unused anyway:
    if ( obj == null)
    throw "can't save a null";
  • use an identical check for null
    if ( obj === null || typeof( obj ) == "undefined" )
    throw "can't save a null";


 Comments   
Comment by auto [ 18/Oct/13 ]

Author:

{u'username': u'FGM', u'name': u'Frederic G. MARAND', u'email': u'fgm@osinet.fr'}

Message: SERVER-11156: Remove useless test from DBCollection.prototype.save().

Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Branch: master
https://github.com/mongodb/mongo/commit/55b49f25f683e7ff86eae40937b0d09d96cfd40d

Comment by Frédéric G. MARAND [ 16/Oct/13 ]

Just sent a pull request https://github.com/mongodb/mongo/pull/521

Comment by Daniel Pasette (Inactive) [ 15/Oct/13 ]

could just drop the second compare as it's implied by the (obj == null).

Generated at Thu Feb 08 03:25:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.