ballerina-platform / ballerina-lang

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

Annotation doesn't get populated before listener init #33594

Open rdhananjaya opened 3 years ago

rdhananjaya commented 3 years ago

Description:

import ballerina/io;

annotation Annot on parameter, class;

@Annot
public service class S {
    resource function default .(@Annot int param) {

    }
}

listener l = new Listener(new S());

public class Listener {
    S s;

    public isolated function 'start() returns error? {
        boolean? a = S.@Annot;
        io:println("From listener.start func: ", a is true);
    }
    public isolated function gracefulStop() returns error? {
    }
    public isolated function immediateStop() returns error? {
    }
    public isolated function detach(service object {} s) returns error? {
    }
    public isolated function attach(service object {} s, string[]|string? name = ()) returns error? {
    }
    isolated function register(service object {} s, string[]|string? name) returns error? {
    }

    public function init(S s) returns error? {
        self.s = s;
        var t = typeof s;
        boolean? a = t.@Annot;
        io:println("From listener init: ", a is true);
    }
}

public function main() {
    boolean? a = S.@Annot;
    io:println("From main func: ", a is true);
}

This seems to be a annotation re-ordering issue. The http team wants to read the annotation from a internal (java) function called from listener init, and the annotation is not populated at that time.

@chamil321 @TharmiganK until this gets fixed, you should be able to use the annotation from a method like start. Steps to reproduce:

Affected Versions:

OS, DB, other environment details and versions:

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

MaryamZi commented 2 months ago

The plan is to properly fix this by incorporating typedesc + annotation changes.