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]: java.lang.NullPointerException #40354

Closed
glennj opened this issue May 6, 2023 · 5 comments · Fixed by #40529
Closed

[Bug]: java.lang.NullPointerException #40354

glennj opened this issue May 6, 2023 · 5 comments · Fixed by #40529
Assignees
Labels
Error/TypeC correct program that results in an incomprehensible/misleading error at runtime needTriage The issue has to be inspected and labeled manually Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Type/Bug userCategory/Compilation

Comments

@glennj
Copy link

glennj commented May 6, 2023

Description

[2023-05-06 22:22:38,884] SEVERE {b7a.log.crash} - null
java.lang.NullPointerException
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.visit(BIROptimizer.java:159)
        at org.wso2.ballerinalang.compiler.bir.model.BIRNode$BIRBasicBlock.accept(BIRNode.java:474)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.lambda$visit$3(BIROptimizer.java:121)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.visit(BIROptimizer.java:121)
        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:107)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer$RHSTempVarOptimizer.visit(BIROptimizer.java:107)
        at org.wso2.ballerinalang.compiler.bir.model.BIRNode$BIRPackage.accept(BIRNode.java:89)
        at org.wso2.ballerinalang.compiler.bir.optimizer.BIROptimizer.optimizePackage(BIROptimizer.java:83)
        at org.wso2.ballerinalang.compiler.bir.BIRGen.genBIR(BIRGen.java:287)
        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: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:171)
        at io.ballerina.projects.JBallerinaBackend.from(JBallerinaBackend.java:116)
        at io.ballerina.cli.task.CompileTask.execute(CompileTask.java:191)
        at io.ballerina.cli.TaskExecutor.executeTasks(TaskExecutor.java:40)
        at io.ballerina.cli.cmd.TestCommand.execute(TestCommand.java:315)
        at java.base/java.util.Optional.ifPresent(Optional.java:183)
        at io.ballerina.cli.launcher.Main.main(Main.java:51)

ERROR [anagram:(1:1,1:1)] Compilation failed due to an unhandled exception
error: compilation contains errors

Steps to Reproduce

https://exercism.org/tracks/ballerina/exercises/anagram

code

public function anagrams(string word, string[] candidates) returns string[] {
    var toKey = function (string w) returns int[] => w.toCodePointInts().sort();
    var lcWord = word.toLowerAscii();
    var key = toKey(lcWord);

    return from string candidate in candidates
           let string lcCand = candidate.toLowerAscii()
           where lcCand != lcWord && key == toKey(lcCand)
           select candidate;
}

Affected Version(s)

$ bal version
Ballerina 2201.5.0 (Swan Lake Update 5)
Language specification 2022R4
Update Tool 1.3.14

OS, DB, other environment details and versions

$ uname -a
Linux exercism-vm 5.10.0-20-amd64 #1 SMP Debian 5.10.158-2 (2022-12-13) x86_64 GNU/Linux

Related area

-> Compilation

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@glennj glennj added the Type/Bug label May 6, 2023
@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels May 6, 2023
@glennj
Copy link
Author

glennj commented May 6, 2023

A resolution:

public function anagrams(string word, string[] candidates) returns string[] {
    var lcWord = word.toLowerAscii();
    var key = keyOf(lcWord);

    return from string candidate in candidates
           let string lcCand = candidate.toLowerAscii()
           where lcCand != lcWord && key == keyOf(lcCand)
           select candidate;
}

function keyOf(string w) returns int[] => w.toCodePointInts().sort();

@hasithaa hasithaa added the Error/TypeC correct program that results in an incomprehensible/misleading error at runtime label May 15, 2023
@github-actions
Copy link

github-actions bot commented Jun 4, 2023

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.

@gimantha gimantha added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Jun 4, 2023
@glennj
Copy link
Author

glennj commented Jun 5, 2023

Sorry what? That I found a workaround for a language bug makes the first attempt an "engineering mistake"? My mistake or yours? Can you point me to some place in the documentation that would tell me the initial version is wrong?

@gimantha
Copy link
Contributor

gimantha commented Jun 6, 2023

Sorry what? That I found a workaround for a language bug makes the first attempt an "engineering mistake"? My mistake or yours? Can you point me to some place in the documentation that would tell me the initial version is wrong?

Hey @glennj The mistake is from our side. :-). Your initial code should have worked properly, but due to a mistake (Probably we have not covered your use-case in the initial testing) done from our side, you encountered this issue. Therefore we marked it as a mistake from our side and the label is only used to categorised them as an engineering mistake done from our side. We closed the issue as we fixed the issue with this pull request: #40529

I am sorry for the confusion.

@glennj
Copy link
Author

glennj commented Jun 6, 2023

Thank you for your gracious reply. I overreacted to the ticket getting closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error/TypeC correct program that results in an incomprehensible/misleading error at runtime needTriage The issue has to be inspected and labeled manually Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Type/Bug userCategory/Compilation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants