self-xdsd / self-core

Self's core, implemented with Java SE 11.
https://self-xdsd.com
Other
28 stars 12 forks source link

GitlabIssueLabels.java: ClassCastException on iterator(). #929

Closed criske closed 3 years ago

criske commented 3 years ago

Reproduce: this happens when pm tries to register a task, after a "register" command.

https://github.com/self-xdsd/self-core/blob/eeb02883804d4ce6448e7f1d5f140f2c3a671a68/self-core-impl/src/main/java/com/selfxdsd/core/GitlabIssueLabels.java#L153-L161

java.lang.ClassCastException: class org.glassfish.json.JsonStringImpl cannot be cast to class javax.json.JsonObject 

(org.glassfish.json.JsonStringImpl and javax.json.JsonObject are in unnamed module of loader 'app')
charlesmike commented 3 years ago

@criske thank you for reporting this. I'll assign someone to take care of it soon.

charlesmike commented 3 years ago

@fellahi-ali this is your task now, please go ahead. Deadline (when this ticket should be closed) is 2021-02-04T19:26:38.132736.

Estimation here is 60 minutes, that's how much you will be paid.

Remember, you don't have to solve everything in this ticket - you can solve it partially and leave todo markers in the code, which will become future tasks.

If you have any questions don't ask me, I'm not a technical person. Open new tickets instead.

If you don't have time or simply don't want to work on this, you can always resign.

criske commented 3 years ago

This is the json issue to test against.

{
    "id":77688395,
    "iid":4,
    "project_id":22690889,
    "title":"todo.txt: This is a todo.",
    "description":"The puzzle ``-1236499963`` originating from #1 has to be resolved:\n\n\"This is a todo.\"\n\nIt is located at todo.txt#1-1. \n\nEstimation is ``30 minutes``.\nIf you have any technical questions, don't ask me, I won't be able to help. Open new issues instead.",
    "state":"opened",
    "created_at":"2021-01-22T14:18:01.686Z",
    "updated_at":"2021-01-25T17:00:13.591Z",
    "closed_at":null,
    "closed_by":null,
    "labels":[
        "30 min",
        "puzzle"
    ],
    "milestone":null,
    "assignees":[

    ],
    "author":{
        "id":6018288,
        "name":"criske",
        "username":"criske",
        "state":"active",
        "avatar_url":"https://secure.gravatar.com/avatar/d50208500191eb9b0d99ed29be6facd5?s=80&d=identicon",
        "web_url":"https://gitlab.com/criske"
    },
    "assignee":null,
    "user_notes_count":10,
    "merge_requests_count":0,
    "upvotes":0,
    "downvotes":0,
    "due_date":null,
    "confidential":false,
    "discussion_locked":null,
    "web_url":"https://gitlab.com/criske/self-xdsd-playground/-/issues/4",
    "time_stats":{
        "time_estimate":0,
        "total_time_spent":0,
        "human_time_estimate":null,
        "human_total_time_spent":null
    },
    "task_completion_status":{
        "count":0,
        "completed_count":0
    },
    "weight":null,
    "blocking_issues_count":0,
    "has_tasks":false,
    "_links":{
        "self":"https://gitlab.com/api/v4/projects/22690889/issues/4",
        "notes":"https://gitlab.com/api/v4/projects/22690889/issues/4/notes",
        "award_emoji":"https://gitlab.com/api/v4/projects/22690889/issues/4/award_emoji",
        "project":"https://gitlab.com/api/v4/projects/22690889"
    },
    "references":{
        "short":"#4",
        "relative":"#4",
        "full":"criske/self-xdsd-playground#4"
    },
    "subscribed":true,
    "moved_to_id":null,
    "service_desk_reply_to":null,
    "health_status":null
}
amihaiemil commented 3 years ago

@fellahi-ali @criske This problem occurs because the labels array returned with the Issue (in the case of Fetch Single Issue) contains only the String texts of the labels, and we expect the array to contain JsonObjects (full label objects containing text, color, id etc).

A simple fix for this is:

    @Override
    public Iterator<Label> iterator() {
        final List<Label> labels = new ArrayList<>();
        final List<JsonString> array = this.issue.getJsonArray("labels")
            .getValuesAs(JsonString.class);
        for(final JsonString label : array) {
            labels.add(
                new GitlabLabel(
                    Json.createObjectBuilder()
                        .add("name", label.getString())
                        .build()
                )
            );
        }
        return labels.iterator();
    }
amihaiemil commented 3 years ago

@fellahi-ali I will fix this quickly now :D

amihaiemil commented 3 years ago

@charlesmike deregister

charlesmike commented 3 years ago

@charlesmike deregister

@amihaiemil ok, I've removed this task from scope. I'm not managing it anymore.

amihaiemil commented 3 years ago

@charlesmike add

charlesmike commented 3 years ago

@charlesmike add

@amihaiemil I've just registered this ticket as a task and will assign it to someone soon. Thanks!

alilosoft commented 3 years ago

@fellahi-ali I will fix this quickly now :D

you have already solved it :D