Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API misuse error from static analyzer

I am getting this error from static analyzer :

This is the code :

API Misuse (Apple) - Dictionary cannot be nil

 - (NSString *)description
{
    return [@{@"filePath": self.filePath,
        @"fileName": self.fileName,
        @"fileAttributes": self.fileAttributes,
        @"creationDate": self.creationDate,
        @"modificationDate": self.modificationDate,
        @"fileSize": @(self.fileSize),
        @"age": @(self.age),
        @"isArchived": @(self.isArchived)} description];
}

Can any one tell what is the problem ?

like image 206
shannoga Avatar asked Dec 29 '25 23:12

shannoga


2 Answers

That chunk of code looks like it's from a older version of Lumberjack's DDFileLogger.m

They got rid of the warning by inserting default empty strings if nil for items in the dictionary -> https://github.com/CocoaLumberjack/CocoaLumberjack/pull/127/files

    return [@{@"filePath": (self.filePath ?: @""),
          @"fileName": (self.fileName ?: @""),
          @"fileAttributes": (self.fileAttributes ?: @""),
          @"creationDate": (self.creationDate ?: @""),
          @"modificationDate": (self.modificationDate ?: @""),
          @"fileSize": @(self.fileSize),
          @"age": @(self.age),
          @"isArchived": @(self.isArchived)} description];
like image 159
vwong2013 Avatar answered Dec 31 '25 11:12

vwong2013


Either one of your values is guaranteed to be nil, or one of your values is not an object pointer, because the following code yields no error at all:

- (NSString *)description
{
    return [@{@"filePath": @"",
          @"fileName": @"",
          @"fileAttributes": @"",
          @"creationDate": @"",
          @"modificationDate": @"",
          @"fileSize": @"",
          @"age": @"",
          @"isArchived": @""} description];
}
like image 37
Joride Avatar answered Dec 31 '25 13:12

Joride



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!