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

Compiler gives NPE if we have a foreach inside query statement #37292

Open
daneshk opened this issue Aug 8, 2022 · 2 comments
Open

Compiler gives NPE if we have a foreach inside query statement #37292

daneshk opened this issue Aug 8, 2022 · 2 comments
Labels
Lang/Expressions/Query Priority/High Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug

Comments

@daneshk
Copy link
Member

daneshk commented Aug 8, 2022

Description:
I am trying to write a gRPC remote function like below,

    remote function RouteChat(RouteGuideRouteNoteCaller caller, stream<RouteNote, grpc:Error?> routeNoteStream) returns error? {
        check from var note in routeNoteStream
            do {
            string key = string `${note.location.longitude} ${note.location.latitude}`;
            RouteNote[]? routeNotes = routeNotesMap[key];
            if routeNotes is RouteNote[] {
                foreach var item in routeNotes {
                    check caller->sendRouteNote(item);
                }
                routeNotes.push(note);
            } else {
                routeNotesMap[key] = [note];
            }
        };
    }

But I am getting the following NPE while building the code.

[2022-08-08 12:16:02,362] SEVERE {b7a.log.crash} - null 
java.lang.NullPointerException
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.visit(BIROptimizer.java:169)
        at org.wso2.ballerinalang.compiler.bir.model.BIRNode$BIRBasicBlock.accept(BIRNode.java:465)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.lambda$visit$4(BIROptimizer.java:131)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.visit(BIROptimizer.java:131)
        at org.wso2.ballerinalang.compiler.bir.model.BIRNode$BIRFunction.accept(BIRNode.java:423)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.lambda$visit$1(BIROptimizer.java:108)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.visit(BIROptimizer.java:108)
        at org.wso2.ballerinalang.compiler.bir.model.BIRNode$BIRPackage.accept(BIRNode.java:89)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer.optimizePackage(BIROptimizer.java:84)
        at org.wso2.ballerinalang.compiler.bir.BIRGen.genBIR(BIRGen.java:273)
        at io.ballerina.projects.internal.CompilerPhaseRunner.birGen(CompilerPhaseRunner.java:220)
        at io.ballerina.projects.internal.CompilerPhaseRunner.performBirGenPhases(CompilerPhaseRunner.java:157)
        at io.ballerina.projects.ModuleContext.generateCodeInternal(ModuleContext.java:447)
        at io.ballerina.projects.ModuleCompilationState$4.generatePlatformSpecificCode(ModuleCompilationState.java:132)
        at io.ballerina.projects.ModuleContext.generatePlatformSpecificCode(ModuleContext.java:381)
        at io.ballerina.projects.JBallerinaBackend.performCodeGen(JBallerinaBackend.java:165)
        at io.ballerina.projects.JBallerinaBackend.<init>(JBallerinaBackend.java:134)
        at io.ballerina.projects.JBallerinaBackend.lambda$from$0(JBallerinaBackend.java:112)
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134)
        at io.ballerina.projects.PackageCompilation.getCompilerBackend(PackageCompilation.java:167)
        at io.ballerina.projects.JBallerinaBackend.from(JBallerinaBackend.java:111)
        at io.ballerina.cli.task.CompileTask.execute(CompileTask.java:142)
        at io.ballerina.cli.TaskExecutor.executeTasks(TaskExecutor.java:40)
        at io.ballerina.cli.cmd.BuildCommand.execute(BuildCommand.java:249)
        at java.base/java.util.Optional.ifPresent(Optional.java:183)
        at io.ballerina.cli.launcher.Main.main(Main.java:51)
@daneshk daneshk added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. labels Aug 8, 2022
@MaryamZi
Copy link
Member

MaryamZi commented Aug 8, 2022

Works when the foreach statement is replaced with another query action.

@pcnfernando
Copy link
Member

Related to #34557

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lang/Expressions/Query Priority/High Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug
Projects
None yet
Development

No branches or pull requests

3 participants