Skip to content

Commit

Permalink
Add file+line to checkNotNull (#1921)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Mar 8, 2024
1 parent 1aa5d91 commit c3ff7e3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cpp/include/Ice/ProxyFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ namespace Ice
/**
* Verifies that a proxy received from the client is not null, and throws a MarshalException if it is.
* @param prx The proxy to check.
* @param file The source file name.
* @param line The source line number.
* @param current The Current object for the invocation.
* @throw MarshalException If the proxy is null.
* */
template<typename Prx, std::enable_if_t<std::is_base_of<ObjectPrx, Prx>::value, bool> = true>
void checkNotNull(std::optional<Prx> prx, const Current& current)
void checkNotNull(std::optional<Prx> prx, const char* file, int line, const Current& current)
{
if (!prx)
{
// Will be reported back to the client as an UnknownLocalException with an error message.
std::ostringstream os;
os << "null proxy passed to " << current.operation << " on object "
<< current.adapter->getCommunicator()->identityToString(current.id);
throw MarshalException{__FILE__, __LINE__, os.str()};
throw MarshalException{file, line, os.str()};
}
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/IceDiscovery/LookupI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,13 @@ LookupReplyI::LookupReplyI(const LookupIPtr& lookup) : _lookup(lookup) {}
void
LookupReplyI::foundObjectById(Identity id, optional<ObjectPrx> proxy, const Current& current)
{
Ice::checkNotNull(proxy, current);
checkNotNull(proxy, __FILE__, __LINE__, current);
_lookup->foundObject(id, current.id.name, *proxy);
}

void
LookupReplyI::foundAdapterById(string adapterId, optional<ObjectPrx> proxy, bool isReplicaGroup, const Current& current)
{
Ice::checkNotNull(proxy, current);
checkNotNull(proxy, __FILE__, __LINE__, current);
_lookup->foundAdapter(adapterId, current.id.name, *proxy, isReplicaGroup);
}
2 changes: 1 addition & 1 deletion cpp/src/IceStorm/NodeI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ NodeI::ready(
int64_t generation,
const Ice::Current& current)
{
Ice::checkNotNull(coordinator, current);
checkNotNull(coordinator, __FILE__, __LINE__, current);
lock_guard lock(_mutex);
if (!_destroy && _state == NodeState::NodeStateReorganization && _group == gn)
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/IceStorm/TopicI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace
optional<Ice::ObjectPrx>
subscribeAndGetPublisher(QoS qos, optional<Ice::ObjectPrx> obj, const Ice::Current& current) override
{
Ice::checkNotNull(obj, current);
checkNotNull(obj, __FILE__, __LINE__, current);
while (true)
{
int64_t generation = -1;
Expand Down Expand Up @@ -149,7 +149,7 @@ namespace

void unsubscribe(optional<Ice::ObjectPrx> subscriber, const Ice::Current& current) override
{
Ice::checkNotNull(subscriber, current);
checkNotNull(subscriber, __FILE__, __LINE__, current);
while (true)
{
int64_t generation = -1;
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/IceStorm/TransientTopicI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ TransientTopicImpl::getNonReplicatedPublisher(const Ice::Current&) const
optional<Ice::ObjectPrx>
TransientTopicImpl::subscribeAndGetPublisher(QoS qos, optional<Ice::ObjectPrx> obj, const Ice::Current& current)
{
Ice::checkNotNull(obj, current);
checkNotNull(obj, __FILE__, __LINE__, current);
Ice::Identity id = obj->ice_getIdentity();

auto traceLevels = _instance->traceLevels();
Expand Down Expand Up @@ -183,7 +183,7 @@ TransientTopicImpl::subscribeAndGetPublisher(QoS qos, optional<Ice::ObjectPrx> o
void
TransientTopicImpl::unsubscribe(optional<Ice::ObjectPrx> subscriber, const Ice::Current& current)
{
Ice::checkNotNull(subscriber, current);
checkNotNull(subscriber, __FILE__, __LINE__, current);
Ice::Identity id = subscriber->ice_getIdentity();

auto traceLevels = _instance->traceLevels();
Expand Down Expand Up @@ -221,7 +221,7 @@ TransientTopicImpl::getLinkProxy(const Ice::Current&)
void
TransientTopicImpl::link(optional<TopicPrx> topic, int cost, const Ice::Current& current)
{
Ice::checkNotNull(topic, current);
checkNotNull(topic, __FILE__, __LINE__, current);
TopicInternalPrx internal(*topic);
auto link = internal->getLinkProxy();

Expand Down

0 comments on commit c3ff7e3

Please sign in to comment.