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

GHMilestone throws NPE on null state #2028

Open
rnveach opened this issue Feb 10, 2025 · 6 comments
Open

GHMilestone throws NPE on null state #2028

rnveach opened this issue Feb 10, 2025 · 6 comments

Comments

@rnveach
Copy link
Contributor

rnveach commented Feb 10, 2025

The following method is not null safe:

public GHMilestoneState getState() {
return Enum.valueOf(GHMilestoneState.class, state.toUpperCase(Locale.ENGLISH));

Whenever it is called to get the state of the milestone, and it (state field) is null, it will throw a NullPointerException.

There is no other method in this class to ascertain the value of this before calling the method. The field is private. Programmers are forced to wrap this in a try/catch in the case it is null.

It would ease handling this call if it had a null check and returned null if there is no state.

@bitwiseman
Copy link
Member

PR welcome.

There's an enum helper class in this library that will supply a default value when enum conversion fails. It just wasn't used here.

@bitwiseman
Copy link
Member

@rnveach
When are you see state value of null?
The docs only mention open or closed: https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#list-milestones

@rnveach
Copy link
Contributor Author

rnveach commented Feb 14, 2025

While scanning https://github.com/checkstyle/checkstyle/issues , I pick up issue 16243. I call GHIssue#listEvents and it eventually gives me a milestone issue event. So I call on that GHIssueEvent#getMilestone to get the milestone. I finally call on that GHMilestone#getState and that is where I run into the NPE issue.

https://api.github.com/repos/checkstyle/checkstyle/issues/16243/events

In my dump of GHMilestone instance in this case, everything is null except title.

Just my assumption not knowing anything and thinking about your question and seeing the events URL, maybe an event milestone (milestone in GHIssueEvent) has less information than standalone querying the actual milestone (GHMilestone)? Maybe you are mixing the 2 up here, and GHIssueEvent#getMilestone should return a smaller class than the full GHMilestone? I have, by no means, any expertise here.

If this is the case, then this issue isn't about null protection, but changing GHIssueEvent#getMilestone's return.

@rnveach
Copy link
Contributor Author

rnveach commented Feb 14, 2025

This seems to be the specific section in the REST API from the link you provided under response schema.
https://docs.github.com/en/rest/issues/events?apiVersion=2022-11-28#list-issue-events

          "milestone": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string"
              }
            },
            "required": [
              "title"
            ]
          }

Only title is expected back here.

@rnveach
Copy link
Contributor Author

rnveach commented Feb 14, 2025

I think this issue also expands to labels returned from GHIssueEvent.

Schema from spec:

          "label": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "color": {
                "type": "string"
              }
            },
            "required": [
              "name",
              "color"
            ]
          }

There is only name and color.

@bitwiseman
Copy link
Member

While scanning https://github.com/checkstyle/checkstyle/issues , I pick up issue 16243.

Ah, different endpoint. Got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants