Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for nulls when using programmer #10033

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,18 @@ private String waitForUploadPort(String uploadPort, List<String> before, boolean
private boolean uploadUsingProgrammer(String buildPath, String className) throws Exception {

TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
if (targetPlatform == null) {
throw new RunnerException(tr("Could not load platform for programmer. Ensure programmer selection is correct for the board."), false);
}
String programmer = PreferencesData.get("programmer");
if (programmer.contains(":")) {
String[] split = programmer.split(":", 2);
targetPlatform = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this could again return null when an invalid package is specified in the "programmer". Or does this throw an exception instead?

Copy link
Author

Choose a reason for hiding this comment

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

As in the other comment. Trying to be defensive AND give a unique error message for future users who ask for support.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit confused. I think this can return null without that resulting in a proper error message (but still a NullPointerException). Maybe you misunderstood my meaning?

programmer = split[1];
}
if (programmer == null) {
throw new RunnerException(tr("Could not load programmer. Ensure programmer selection is correct for the board."), false);
}

PreferencesMap prefs = PreferencesData.getMap();
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
Expand Down