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]: Getting NPE for a simple test with the Dead Code Elimination #43552

Closed
TharmiganK opened this issue Nov 6, 2024 · 5 comments
Closed
Assignees
Labels
Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation

Comments

@TharmiganK
Copy link
Contributor

TharmiganK commented Nov 6, 2024

Description

Getting the following error when running a simple test assertion with string includes API.

This is found while checking url module with dead code elimination(Related task - ballerina-platform/ballerina-library#7339)

[2024-11-06 13:02:06,298] SEVERE {b7a.log.crash} - Cannot invoke "io.ballerina.runtime.internal.values.FPValue.getFunction()" because "<local1>" is null 
java.lang.NullPointerException: Cannot invoke "io.ballerina.runtime.internal.values.FPValue.getFunction()" because "<local1>" is null
        at tharmigan.package$test.0.tests.test.test(tests/test.bal:6)
        at tharmigan.package$test.0.lambdas.$_generated1tests.test_execute-generated_1.test$lambda0$(tests/test_execute-generated_1.bal:4)
        at io.ballerina.runtime.internal.scheduling.SchedulerItem.execute(SchedulerItem.java:54)
        at io.ballerina.runtime.internal.scheduling.Scheduler.run(Scheduler.java:324)
        at io.ballerina.runtime.internal.scheduling.Scheduler.runSafely(Scheduler.java:291)
        at java.base/java.lang.Thread.run(Thread.java:840)

Steps to Reproduce

Try to run the following test with dead code elimination feature:

import ballerina/test;

@test:Config
function test() {
    string result = "a";
    test:assertTrue(result.includes(" "));
}
Compiling source
        tharmigan/package:0.1.0
Duration for unused BIR node analysis : 1ms
    tharmigan/package:0.1.0 : 1ms


Running Tests

        package
[2024-11-06 13:02:06,298] SEVERE {b7a.log.crash} - Cannot invoke "io.ballerina.runtime.internal.values.FPValue.getFunction()" because "<local1>" is null 
java.lang.NullPointerException: Cannot invoke "io.ballerina.runtime.internal.values.FPValue.getFunction()" because "<local1>" is null
        at tharmigan.package$test.0.tests.test.test(tests/test.bal:6)
        at tharmigan.package$test.0.lambdas.$_generated1tests.test_execute-generated_1.test$lambda0$(tests/test_execute-generated_1.bal:4)
        at io.ballerina.runtime.internal.scheduling.SchedulerItem.execute(SchedulerItem.java:54)
        at io.ballerina.runtime.internal.scheduling.Scheduler.run(Scheduler.java:324)
        at io.ballerina.runtime.internal.scheduling.Scheduler.runSafely(Scheduler.java:291)
        at java.base/java.lang.Thread.run(Thread.java:840)
 

        test has failed.


                [fail] test:

                    error("java.lang.NullPointerException: Cannot invoke "io.ballerina.runtime.internal.values.FPValue.getFunction()" because "<local1>" is null")
                                callableName: test moduleName: tharmigan.package$test.0.tests.test fileName: tests/test.bal lineNumber: 6
                                callableName: test$lambda0$ moduleName: tharmigan.package$test.0.tests.test_execute-generated_1 fileName: tests/test_execute-generated_1.bal lineNumber: 4



                0 passing
                1 failing
                0 skipped

                Test execution time : 0.048s
error: there are test failures

Affected Version(s)

Ballerina SwanLake Update 11(2201.11.x)

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

@MaryamZi
Copy link
Member

MaryamZi commented Nov 7, 2024

Seems to be happening with langlib function calls.

Reproducible when the function is in the source too, rather than tests.

Source

public function includesFn(string a, string b) returns boolean {
    return a.includes(b);
}

Tests

import ballerina/test;

@test:Config
function test() {
    boolean res = includesFn("foo", "bar");
    test:assertFalse(res);
}

Issue could be related to io.ballerina.projects.UsedBIRNodeAnalyzer.InvocationData#registerNodes since the function pool is not populated for langlibs.

@MaryamZi
Copy link
Member

MaryamZi commented Nov 8, 2024

Seems like the error goes away when the start index is provided.

E.g.,

return a.includes(b, 4);

@MaryamZi
Copy link
Member

We've added some fixes which are available with 2201.11.0-20241111-101700-af28a18f, can you please check with this version?

@MaryamZi MaryamZi added Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. and removed needTriage The issue has to be inspected and labeled manually labels Nov 11, 2024
@TharmiganK
Copy link
Contributor Author

We've added some fixes which are available with 2201.11.0-20241111-101700-af28a18f, can you please check with this version?

With the provided timestamped version, the tests are running without any NPE issues. Hence closing this issue

Copy link

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 Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Type/Bug userCategory/Compilation
Projects
None yet
Development

No branches or pull requests

5 participants