ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.58k stars 738 forks source link

[Bug]: Annotation Values for Resource Method Types are not Present in the Runtime #43162

Closed ThisaruGuruge closed 1 month ago

ThisaruGuruge commented 1 month ago

Description

When the getAnnotation() or getAnnotations() method is called on the ResourceMethodType value, the annotations are not present even though the annotations are added in the Ballerina code.

Steps to Reproduce

Consider the following Ballerina code:

import ballerina/graphql;

@graphql:ServiceConfig {
    cacheConfig: {}
}
service on new graphql:Listener(9090) {

    @graphql:ResourceConfig {
        cacheConfig: {
            maxAge: 60
        }
    }
    resource function get greeting() returns string {
        return "Hello, World!";
    }

    resource function get profile(string name) returns Profile {
        return new(name);
    }
}

public isolated distinct service class Profile {
    private final string name;

    public isolated function init(string name) {
        [self.name](http://self.name/) = name;
    }

    @graphql:ResourceConfig {
        cacheConfig: {
            maxAge: 60
        }
    }
    isolated resource function get name() returns string => [self.name](http://self.name/);
}

We pass the BObject value of the GraphQL service object to the native code when the service is attached to the listener. In the native code, the annotations for the greeting resource are there.

Then we iterate through the ResourceMethodType values of the service object, and when try to access the annotations of the resource methods of the Profile type, the getAnnotations API returns null, even though the get name() resource does have an annotation. This is a blocker for https://github.com/ballerina-platform/ballerina-library/issues/6722 where the annotation values cannot be accessed so the complexity values are incorrect.

Affected Version(s)

No response

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

MaryamZi commented 1 month ago

May be the same issue as https://github.com/ballerina-platform/ballerina-lang/issues/43122, for which there is already a PR https://github.com/ballerina-platform/ballerina-lang/pull/43121.

I'll also check, but FYI @HindujaB.

MaryamZi commented 1 month ago

Seems like it is not the type reference issue. But could be https://github.com/ballerina-platform/ballerina-lang/issues/33594, https://github.com/ballerina-platform/ballerina-lang/issues/42906#issuecomment-2227344070 (as Hinduja is also checking), if access is in the attach method.

Can we consider accessing at a method like start if this is the case?

ThisaruGuruge commented 1 month ago

Moving to the start method solved the issue, but we need a proper fix. But considering the time constraints, we are going ahead with this fix.

HindujaB commented 1 month ago

As we have an issue [1] that follows up with original cause and the provided workaround is working, I am closing the issue. Please feels free to reopen if there's any concern.

[1] https://github.com/ballerina-platform/ballerina-lang/issues/33594

github-actions[bot] commented 1 month ago

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.