Compiler run time crashed with the following error
Compiling source
ballerina/graphql:1.6.2
ballerina: Oh no, something really went wrong. Bad. Sad.
We appreciate it if you can report the code that broke Ballerina in
https://github.com/ballerina-platform/ballerina-lang/issues with the
log you get below and your sample code.
We thank you for helping make us better.
[2023-03-01 13:16:38,793] SEVERE {b7a.log.crash} - null
java.lang.NullPointerException
at org.wso2.ballerinalang.compiler.desugar.Desugar.getInvocation(Desugar.java:6459)
at org.wso2.ballerinalang.compiler.desugar.Desugar.createStmtExpr(Desugar.java:6434)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:6379)
at org.wso2.ballerinalang.compiler.tree.expressions.BLangInvocation.accept(BLangInvocation.java:128)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewriteExpr(Desugar.java:8926)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:3526)
at org.wso2.ballerinalang.compiler.tree.statements.BLangExpressionStmt.accept(BLangExpressionStmt.java:51)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8901)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8939)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewriteStmt(Desugar.java:8945)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:1607)
at org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt.accept(BLangBlockStmt.java:65)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8901)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8939)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:3533)
at org.wso2.ballerinalang.compiler.tree.statements.BLangIf.accept(BLangIf.java:60)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8901)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8939)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewriteStmt(Desugar.java:8945)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:1607)
at org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt.accept(BLangBlockStmt.java:65)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8901)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8939)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:5360)
at org.wso2.ballerinalang.compiler.tree.statements.BLangWhile.accept(BLangWhile.java:81)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8901)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8939)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewriteStmt(Desugar.java:8945)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:1380)
at org.wso2.ballerinalang.compiler.tree.BLangBlockFunctionBody.accept(BLangBlockFunctionBody.java:60)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8901)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:1426)
at org.wso2.ballerinalang.compiler.tree.BLangFunction.accept(BLangFunction.java:76)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8901)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:1176)
at org.wso2.ballerinalang.compiler.tree.BLangClassDefinition.accept(BLangClassDefinition.java:124)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8901)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8952)
at org.wso2.ballerinalang.compiler.desugar.Desugar.visit(Desugar.java:811)
at org.wso2.ballerinalang.compiler.tree.BLangPackage.accept(BLangPackage.java:167)
at org.wso2.ballerinalang.compiler.desugar.Desugar.rewrite(Desugar.java:8901)
at org.wso2.ballerinalang.compiler.desugar.Desugar.perform(Desugar.java:473)
at io.ballerina.projects.internal.CompilerPhaseRunner.desugar(CompilerPhaseRunner.java:216)
at io.ballerina.projects.internal.CompilerPhaseRunner.performBirGenPhases(CompilerPhaseRunner.java:152)
at io.ballerina.projects.ModuleContext.generateCodeInternal(ModuleContext.java:451)
at io.ballerina.projects.ModuleCompilationState$4.generatePlatformSpecificCode(ModuleCompilationState.java:132)
at io.ballerina.projects.ModuleContext.generatePlatformSpecificCode(ModuleContext.java:385)
at io.ballerina.projects.JBallerinaBackend.performCodeGen(JBallerinaBackend.java:170)
at io.ballerina.projects.JBallerinaBackend.<init>(JBallerinaBackend.java:139)
at io.ballerina.projects.JBallerinaBackend.lambda$from$0(JBallerinaBackend.java:117)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134)
at io.ballerina.projects.PackageCompilation.getCompilerBackend(PackageCompilation.java:170)
at io.ballerina.projects.JBallerinaBackend.from(JBallerinaBackend.java:116)
at io.ballerina.cli.task.CompileTask.execute(CompileTask.java:165)
at io.ballerina.cli.TaskExecutor.executeTasks(TaskExecutor.java:40)
at io.ballerina.cli.cmd.PackCommand.execute(PackCommand.java:250)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at io.ballerina.cli.launcher.Main.main(Main.java:51)
ERROR [graphql:(1:1,1:1)] Compilation failed due to an unhandled exception
error: compilation contains errors
Steps to Reproduce
Add following function to the field.bal file of the module-ballerina-graphql repository.
isolated function getFieldObjects(parser:SelectionNode selectionNode, __Type 'type) returns Field[] {
Field[] result = [];
(string|int)[] path = self.path;
__Type fieldType = 'type;
__Field[]? typeFields = 'fieldType.fields;
while typeFields is () {
if fieldType.kind == LIST {
path.push("@");
}
__Type? ofType = fieldType.ofType;
if ofType is () {
return result;
}
fieldType = ofType;
typeFields = fieldType.fields;
}
foreach parser:SelectionNode selection in selectionNode.getSelections() {
if selection is parser:FieldNode {
string name = selection.getName();
foreach __Field 'field in <__Field[]>typeFields {
if 'field.name == name {
result.push(new Field(selection, fieldType, (), [...path, selectionNode.getName()],
self.operationType, self.resourcePath));
break;
}
}
} else {
foreach parser:SelectionNode fragmentSelectionNode in selectionNode.getSelections() {
result.push(...self.getFieldObjects(fragmentSelectionNode, fieldType)); // Compilation get successful if this line commented out
}
}
}
return result;
}
- Run `.\gradlew clean build`
The compilation runtime crashes only if the commented line is there and compilation get successful when it is refactored as below.
```ballerina
Field[] fieldsToPush = self.getFieldObjects(fragmentSelectionNode, fieldType);
result.push(...fieldsToPush);
Description
Compiler run time crashed with the following error
Steps to Reproduce
Add following function to the field.bal file of the
module-ballerina-graphql
repository.Affected Version(s)
2201.4.0
OS, DB, other environment details and versions
Related area
-> Runtime
Related issue(s) (optional)
No response
Suggested label(s) (optional)
No response
Suggested assignee(s) (optional)
No response