[ 
https://issues.apache.org/jira/browse/THRIFT-3750?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Zach Howe updated THRIFT-3750:
------------------------------
    Description: 
The NSCopying copyWithZone: implementation does not check isSet. This causes 
the copy not to be a true copy, since all the isSet properties will be set to 
YES on the newly copied object.

Note, updating to provide some more clarity:

In this example, it's fixed:
{code}
- (instancetype) copyWithZone:(NSZone *)zone
{
  Foo * val = [Foo new];
  if (_nameIsSet)
  {
    val.name = [self.name copy];
  }
  return val;
}
{code}

Without the if check on _nameIsSet, the newly copied object will have 
_nameIsSet set to YES but with a nil name.

{code}
- (void) setName: (NSString *) name {
  _name = name;
  _nameIsSet = YES;
}
{code}

  was:The NSCopying copyWithZone: implementation does not check isSet. This 
causes the copy not to be a true copy, since all the isSet properties will be 
set to YES on the newly copied object.


> NSCopying copyWithZone: implementation does not check isSet
> -----------------------------------------------------------
>
>                 Key: THRIFT-3750
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3750
>             Project: Thrift
>          Issue Type: Bug
>          Components: Cocoa - Compiler
>            Reporter: Zach Howe
>            Priority: Critical
>
> The NSCopying copyWithZone: implementation does not check isSet. This causes 
> the copy not to be a true copy, since all the isSet properties will be set to 
> YES on the newly copied object.
> Note, updating to provide some more clarity:
> In this example, it's fixed:
> {code}
> - (instancetype) copyWithZone:(NSZone *)zone
> {
>   Foo * val = [Foo new];
>   if (_nameIsSet)
>   {
>     val.name = [self.name copy];
>   }
>   return val;
> }
> {code}
> Without the if check on _nameIsSet, the newly copied object will have 
> _nameIsSet set to YES but with a nil name.
> {code}
> - (void) setName: (NSString *) name {
>   _name = name;
>   _nameIsSet = YES;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to