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]: Cannot invoke "io.ballerina.runtime.internal.values.MapValue.get(Object)" because "entry" is null when using query expressions #43409

Closed
gimantha opened this issue Sep 23, 2024 · 2 comments
Assignees
Labels
Lang/Expressions/Query Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug
Milestone

Comments

@gimantha
Copy link
Contributor

Description

Consider the code below.

type Period record {
    string date;
    SomeClass[] someClass;
};

type TimeData record {
    string date;
    string section;
    string sectionPercent;
    string sectionCode;
};

type SomeClass record {
    string section;
    string sectionPercent;
    string sectionCode;
};

type Metadata record {
    string section;
    string sectionCode;
};

type Result record {|
    string accountId;
    Metadata[] assetClassList;
    Period[] periods;
|};

function fn(string accountId, TimeData[] timeData) returns Result {
    Period[] periods = [];

    string[] distinctDates = from var item in timeData
        let var date = item.date
        group by date
        select date;

    foreach string date in distinctDates {
        SomeClass[] someClass = from var item in timeData
            where item.date == date
            let var section = item.section
            let var sectionCode = item.section
            let var sectionPercent = item.sectionPercent
            group by section, sectionCode, sectionPercent
            select {section, sectionCode, sectionPercent};
        Period period = {
            date: date,
            someClass
        };
        periods.push(period);
    }

    Metadata[] metadata = from var item in timeData
        let var section = item.section
        let var sectionCode = item.sectionCode
        group by section, sectionCode
        select {section, sectionCode};

    return {
        accountId: accountId,
        assetClassList: metadata,
        periods: periods
    };
}

function fnC(string accountId, TimeData[] timeData) {
    future<Result>[] frs = [];

    foreach int i in 0 ... 100 {
        future<Result> fr = start fn(accountId, timeData);
        frs.push(fr);
    }

    foreach future<Result> item in frs {
        Result|error res = wait item;
    }
}

public function main() {
    future<()>[] frs = [];
    TimeData[] td = from int i in 1000 ... 2000
        let var val = i.toString()
        select {
            date: val,
            sectionPercent: val,
            sectionCode: val,
            section: val
        };

    foreach int i in 1000 ... 2000 {
        future<()> fr = start fnC(i.toString(), td);
        frs.push(fr);
    }

    foreach future<()> item in frs {
        error? unionResult = wait item;
    }
}

When running the above code, the following exception is thrown.

[2024-09-11 22:55:34,335] SEVERE {b7a.log.crash} - Cannot invoke "io.ballerina.runtime.internal.values.MapValue.get(Object)" because "entry" is null
java.lang.NullPointerException: Cannot invoke "io.ballerina.runtime.internal.values.MapValue.get(Object)" because "entry" is null
        at ballerina.lang&0046query.0.$value$_GroupByFunction.convertToStream(types.bal:694)
        at ballerina.lang&0046query.0.$value$_GroupByFunction.call(types.bal)
        at ballerina.lang&0046query.0.$value$_GroupByFunction.process(types.bal:665)
        at ballerina.lang&0046query.0.$value$_GroupByFunction.call(types.bal)
        at ballerina.lang&0046query.0.$value$_SelectFunction.process(types.bal:783)
        at ballerina.lang&0046query.0.$value$_SelectFunction.call(types.bal)
        at ballerina.lang&0046query.0.types.$gen$$anon$method$delegate$_StreamFunction&0046process$0(types.bal:93)
        at ballerina.lang&0046query.0.$value$_StreamPipeline.$gen$$anon$method$delegate$_StreamFunction&0046process$0$lambda0$(types.bal)
        at io.ballerina.runtime.internal.scheduling.SchedulerItem.execute(SchedulerItem.java:54)
        at io.ballerina.runtime.internal.scheduling.Scheduler.run(Scheduler.java:320)
        at io.ballerina.runtime.internal.scheduling.Scheduler.runSafely(Scheduler.java:287)
        at java.base/java.lang.Thread.run(Thread.java:833)

error: java.lang.NullPointerException: Cannot invoke "io.ballerina.runtime.internal.values.MapValue.get(Object)" because "entry" is null
        at ballerina.lang.query.0._GroupByFunction:convertToStream(types.bal:694)
           ballerina.lang.query.0._GroupByFunction:process(types.bal:665)
           ballerina.lang.query.0._SelectFunction:process(types.bal:783)
           ballerina.lang.query.0:$anon$method$delegate$_StreamFunction.process$0(types.bal:93)

Steps to Reproduce

No response

Affected Version(s)

2201.8.x, 2201.9.x, 2201.10.x

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

@gimantha gimantha self-assigned this Sep 23, 2024
@gimantha gimantha moved this to In Progress in Ballerina Team Main Board Sep 23, 2024
@ballerina-bot ballerina-bot added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label Sep 23, 2024
@gimantha gimantha changed the title [Bug]: [Bug]: Cannot invoke "io.ballerina.runtime.internal.values.MapValue.get(Object)" because "entry" is null when using query expressions Sep 23, 2024
@gimantha gimantha moved this from In Progress to On Hold in Ballerina Team Main Board Sep 26, 2024
@gimantha
Copy link
Contributor Author

This issue will be fixed once #43353 is merged into master

Copy link

github-actions bot commented Jan 2, 2025

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.

@NipunaMadhushan NipunaMadhushan added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lang/Expressions/Query Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants