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

[Bug]: Getting NoSuchElementException when checking equality between a record and empty map - {} #43880

Open
TharmiganK opened this issue Mar 6, 2025 · 0 comments · May be fixed by #43883
Open
Assignees
Labels
Area/RuntimeTypeChecker JBallerina runtime type checking related issues Type/Bug

Comments

@TharmiganK
Copy link
Contributor

Description

$Subject

Steps to Reproduce

Try to run this ballerina program with update 12:

import ballerina/io;
import ballerina/time;

enum Gender {
    MALE,
    FEMALE
}

type Employee record {|
    readonly string empNo;
    string firstName;
    string lastName;
    time:Date birthDate;
    Gender gender;
    time:Date hireDate;

    Department department;
    Department? headOf;
    Workspace workspace;
|};

type Workspace record {|
    readonly string workspaceId;
    string workspaceType;

    Building location;
    Employee[] employees;
|};

type Building record {|
    readonly string buildingCode;
    string city;
    string state;
    string country;
    string postalCode;
    string 'type;

    Workspace[] workspaces;
|};

type Department record {|
    readonly string deptNo;
    string deptName;

    Employee[] employees;
    Employee departmentHead;
|};

type OrderItem record {|
    readonly string orderId;
    readonly string itemId;
    int quantity;
    string notes;
|};

public type RedisMetadata record {|
    string entityName;
    string collectionName;
    map<FieldMetadata> fieldMetadata;
    string[] keyFields;
    map<RefMetadata> refMetadata?;
|};

public type EntityFieldMetadata record {|
    RelationMetadata relation;
|};

public type SimpleFieldMetadata record {|
    string fieldName;
    DataType fieldDataType;
|};

public type FieldMetadata SimpleFieldMetadata|EntityFieldMetadata;

public type RelationMetadata record {|
    string entityName;
    string refField;
    DataType refFieldDataType;
|};

public type RefMetadata record {|
    typedesc<record {}> entity;
    string fieldName;
    string refCollection;
    string refMetaDataKey?;
    string[] refFields;
    string[] joinFields;
    string joinCollection?;
    string[] joiningRefFields?;
    string[] joiningJoinFields?;
    CardinalityType 'type;
|};

public enum CardinalityType {
    ONE_TO_ONE,
    ONE_TO_MANY,
    MANY_TO_ONE
}

public enum DataType {
    INT,
    STRING,
    FLOAT,
    DECIMAL,
    BOOLEAN,
    DATE,
    TIME_OF_DAY,
    CIVIL,
    UTC,
    ENUM
}

enum RedisDataType {
    REDIS_STRING = "string",
    REDIS_SET = "set",
    REDIS_HASH = "hash"
}

enum MetaData {
    FIELD_DATA_TYPE = "fieldDataType",
    RELATION = "relation",
    REF_FIELD_DATA_TYPE = "refFieldDataType"
}

public function main() {

    record {|RedisMetadata...;|} & readonly metadata = {
        ["EMPLOYEE"]: {
            entityName: "Employee",
            collectionName: "Employee",
            fieldMetadata: {
                empNo: {fieldName: "empNo", fieldDataType: STRING},
                firstName: {fieldName: "firstName", fieldDataType: STRING},
                lastName: {fieldName: "lastName", fieldDataType: STRING},
                birthDate: {fieldName: "birthDate", fieldDataType: DATE},
                gender: {fieldName: "gender", fieldDataType: ENUM},
                hireDate: {fieldName: "hireDate", fieldDataType: DATE},
                departmentDeptNo: {fieldName: "departmentDeptNo", fieldDataType: STRING},
                workspaceWorkspaceId: {fieldName: "workspaceWorkspaceId", fieldDataType: STRING},
                "department.deptNo": {
                    relation: {
                        entityName: "department",
                        refField: "deptNo",
                        refFieldDataType: STRING
                    }
                },
                "department.deptName": {
                    relation: {
                        entityName: "department",
                        refField: "deptName",
                        refFieldDataType: STRING
                    }
                },
                "workspace.workspaceId": {
                    relation: {
                        entityName: "workspace",
                        refField: "workspaceId",
                        refFieldDataType: STRING
                    }
                },
                "workspace.workspaceType": {
                    relation: {
                        entityName: "workspace",
                        refField: "workspaceType",
                        refFieldDataType: STRING
                    }
                },
                "workspace.locationBuildingCode": {
                    relation: {
                        entityName: "workspace",
                        refField: "locationBuildingCode",
                        refFieldDataType: STRING
                    }
                }
            },
            keyFields: ["empNo"],
            refMetadata: {
                department: {
                    entity: Department,
                    fieldName: "department",
                    refCollection: "Department",
                    refMetaDataKey: "employees",
                    refFields: ["deptNo"],
                    joinFields: ["departmentDeptNo"],
                    'type: ONE_TO_MANY
                },
                workspace: {
                    entity: Workspace,
                    fieldName: "workspace",
                    refCollection: "Workspace",
                    refMetaDataKey: "employees",
                    refFields: ["workspaceId"],
                    joinFields: ["workspaceWorkspaceId"],
                    'type: ONE_TO_MANY
                }
            }
        }
    };
    RedisMetadata & readonly redisMetadata = metadata.get("EMPLOYEE");
    map<RefMetadata> refMetadata = redisMetadata.refMetadata ?: {};
    if refMetadata != {} {
        io:println("Ref metadata is not empty");
    } else {
        io:println("Ref metadata is empty");
    }
}

Affected Version(s)

Ballerina SwanLake Update 12(2201.12.0)

OS, DB, other environment details and versions

No response

Related area

-> Runtime

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label Mar 6, 2025
@TharmiganK TharmiganK added Area/RuntimeTypeChecker JBallerina runtime type checking related issues and removed Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime labels Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/RuntimeTypeChecker JBallerina runtime type checking related issues Type/Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants