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]: The compiler crashes when a variable is passed dynamically to a TCP connection service initializer #43368

Open
nipunayf opened this issue Sep 9, 2024 · 0 comments
Labels
Area/BIR Compiler BIR related issues #Compiler Fix/Crash All issues caused by NPE, CCE, etc Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug

Comments

@nipunayf
Copy link
Contributor

nipunayf commented Sep 9, 2024

Description

$title occurs when a variable is passed within a loop: return new EchoService(port);. However, the code compiles successfully if an integer literal is used: return new EchoService(1122);.

Crash Log
[2024-09-09 11:23:33,141] SEVERE {b7a.log.crash} - Cannot read field "kind" because "moveIns.rhsOp.variableDcl" is null 
java.lang.NullPointerException: Cannot read field "kind" because "moveIns.rhsOp.variableDcl" is null
        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:485)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.lambda$visit$3(BIROptimizer.java:131)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        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:432)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.lambda$visit$1(BIROptimizer.java:117)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.visit(BIROptimizer.java:117)
        at org.wso2.ballerinalang.compiler.bir.model.BIRNode$BIRPackage.accept(BIRNode.java:89)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer.optimizePackage(BIROptimizer.java:89)
        at org.wso2.ballerinalang.compiler.bir.BIRGen.genBIR(BIRGen.java:293)
        at io.ballerina.projects.internal.CompilerPhaseRunner.birGen(CompilerPhaseRunner.java:210)
        at io.ballerina.projects.internal.CompilerPhaseRunner.performBirGenPhases(CompilerPhaseRunner.java:147)
        at io.ballerina.projects.ModuleContext.generateCodeInternal(ModuleContext.java:418)
        at io.ballerina.projects.ModuleCompilationState$4.generatePlatformSpecificCode(ModuleCompilationState.java:132)
        at io.ballerina.projects.ModuleContext.generatePlatformSpecificCode(ModuleContext.java:351)
        at io.ballerina.projects.JBallerinaBackend.performCodeGen(JBallerinaBackend.java:176)
        at io.ballerina.projects.JBallerinaBackend.<init>(JBallerinaBackend.java:145)
        at io.ballerina.projects.JBallerinaBackend.lambda$from$0(JBallerinaBackend.java:129)
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1220)
        at io.ballerina.projects.PackageCompilation.getCompilerBackend(PackageCompilation.java:179)
        at io.ballerina.projects.JBallerinaBackend.from(JBallerinaBackend.java:128)
        at io.ballerina.projects.JBallerinaBackend.from(JBallerinaBackend.java:116)
        at io.ballerina.cli.task.CompileTask.execute(CompileTask.java:232)
        at io.ballerina.cli.TaskExecutor.executeTasks(TaskExecutor.java:40)
        at io.ballerina.cli.cmd.RunCommand.execute(RunCommand.java:304)
        at java.base/java.util.Optional.ifPresent(Optional.java:178)
        at io.ballerina.cli.launcher.Main.main(Main.java:59)

Steps to Reproduce

Compile the following Ballerina code.

import ballerina/io;
import ballerina/tcp;

int[] portList = [8080, 8081, 8082];

public function main() returns error? {
    foreach int port in portList {
        tcp:Service tcpService = service object {
            remote function onConnect(tcp:Caller caller) returns tcp:ConnectionService {
                return new EchoService(port);
            }
        };
    }
}

service class EchoService {
    *tcp:ConnectionService;

    function init(int port) {

    }

    remote function onBytes(tcp:Caller caller, readonly & byte[] data) returns tcp:Error? {
        io:println("Echo: ", string:fromBytes(data));
        check caller->writeBytes(data);
    }
}

Affected Version(s)

Ballerina 2201.10.0

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

@nipunayf nipunayf added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Area/BIR Compiler BIR related issues #Compiler Fix/Crash All issues caused by NPE, CCE, etc labels Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/BIR Compiler BIR related issues #Compiler Fix/Crash All issues caused by NPE, CCE, etc 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

1 participant