Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Check for nulls when using programmer#10033

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tedder wants to merge2 commits intoarduino:master
base:master
Choose a base branch
Loading
fromtedder:ted/test_for_programmer_npe

Conversation

@tedder
Copy link

Try to test and gracefully fail rather than throwing a NullPointerException.

See#10032 for an example of this exception being thrown.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other openPull Requests for the same update/change?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes

I havenot compiled or run tests or linted this. I'm hoping this is a change that someone can shepherd into an upcoming release.

Try to test and gracefully fail rather than throwing a NullPointerException.Seearduino#10032 for an example of this exception being thrown.
Stringprogrammer =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 returnnullwithout that resulting in a proper error message (but still a NullPointerException). Maybe you misunderstood my meaning?


TargetPlatformtargetPlatform =BaseNoGui.getTargetPlatform();
if (targetPlatform ==null) {
thrownewRunnerException(tr("Gould not load platform for programmer. Ensure programmer selection is correct for the board."),false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you have any ideawhytargetPlatform might end up null? Is this when an invalid board is selected? I think this is still unrelated to having a programmer selected?

Copy link
Author

Choose a reason for hiding this comment

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

here's where GetTargetPlatform returns null. I think it might be when a programmer that isn't connected is selected.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that this is related to the selected programmer, and I'm pretty sure that the IDE doesn't actually check for a connected programmer at all (it does not know how, often programmers have specific USB interfaces that the IDE does not know about).

In this case, I think the "targetPlatform" is based on the target package and platform preferences, which, along with the board preference, together indicate the selected board. So I guess the getTargetPlatform can return null when no board is selected (which might not be possible, since there is always a default board selected I think), or when the currently selected board is no longer available (because the platform was uninstalled, or the board was removed from it in an update).

So I guess the error message should talk about the board selection, rather than the programmer selection?

Have you been able to specifically reproduce this null, to verify that it is handled correctly with your PR?

Copy link
Author

Choose a reason for hiding this comment

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

I haven't set up a build environment. I was hoping this would be a start for a core maintainer to take on. If you don't think it's helpful, that's fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

AH, I see you already said you didn't compile this, sorry for missing that. I think this is helpful, but the error messages probably need a bit more tweaking to be a bit more appropriate :-)

As for a maintainer taking this on, with all the load that is already there, I would not expect that to happen quickly, but maybe some other contributor can work on top of this (I won't have time for it, probably).

tedder reacted with thumbs up emoji
@cmaglie
Copy link
Member

The best fix for this is changingBaseNoGui.getTargetPlatform() to return anOptional<TargetPlatform> instead of aTargetPlatform.

This change will trigger compile errors on every place wheregetTargetPlatform is used: at this point all the errors should be fixed by porting the old code to theOptional API and, at the same, audit the code and see if theOptinal.empty() (previouslynull) is handled correctly on every place.

hlovdal reacted with thumbs up emoji

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign ourContributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let usrecheck it.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@matthijskooijmanmatthijskooijmanmatthijskooijman left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@tedder@cmaglie@CLAassistant@matthijskooijman

[8]ページ先頭

©2009-2025 Movatter.jp