Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Fix nil deploymentkey crash #109

Closed
wants to merge 3 commits into from
Closed

Conversation

ryuyu
Copy link
Member

@ryuyu ryuyu commented Apr 28, 2016

Fixes a crash that was caused by attempting to report status when the deployment key wasn't specified in config.xml.

Addresses #108

@lostintangent @geof90

…yment key to updateSuccess so we can report and run without a config.xml deployment key specified
@@ -58,10 +58,14 @@ - (void)handleUnconfirmedInstall:(BOOL)navigate {
}

- (void)updateSuccess:(CDVInvokedUrlCommand *)command {
NSString* deploymentKey = [command argumentAtIndex:0 withDefault:nil andClass:[NSString class]];
if ([deploymentKey length] == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this nil proof?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Calling length on nil will return 0.

// no-op becuase we don't care if we didn't get a deployment key from script; we will just try to use the one from preferences
}

if (deploymentKey.equals(null) || deploymentKey.equals("") || deploymentKey.equals("null") || deploymentKey.equals("undefined")) {
Copy link
Contributor

@geof90 geof90 Apr 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deploymentKey.equals(null) will never be true. If deploymentKey == null, deploymentKey.equals(null) will throw a NullPointerException because you are invoking the equals method on a null object ref. You really want to check for deploymentKey == null.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Forogt about that. Fixed.

@scottbommarito
Copy link

imo I think this problem is a little more complex than this solution.

basically, we now have 3 separate deployment keys
1 - deployment key in config.xml
2 - deployment key passed to checkForUpdate
3 - "default" deployment key (used when 1 and 2 are unspecified)

right now, the default key is null. when we don't have a key in config.xml and no key was passed into checkForUpdate, then we crash.

I agree with @dlebu 's assessment that we can be smarter in our native code to prevent the default key from being null. I like adding the deployment key as an argument to notifyApplicationReady, but I think that if the deployment key is unspecified, it should use the key used in the last call to checkForUpdate (when you call notifyApplicationReady you're probably trying to validate the last update u checked for). If not, it should use the key in the config.xml.

} catch (PackageManager.NameNotFoundException e) {
// Should not happen unless the appVersion is not specified, in which case we can't report anything anyway.
e.printStackTrace();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this code removed, wouldn't that mean we wont be able to report binary updates?

@ryuyu
Copy link
Member Author

ryuyu commented Apr 28, 2016

Pulling this PR in favor of minimum change required to unblock.

@ryuyu ryuyu closed this Apr 28, 2016
@lostintangent lostintangent deleted the fix-nil-deploymentkey-crash branch June 19, 2016 17:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants