ballerina-platform / ballerina-lang

The Ballerina Programming Language
https://ballerina.io/
Apache License 2.0
3.66k stars 749 forks source link

Compile time check not working for () values return from stream.next() function #31671

Closed hevayo closed 2 years ago

hevayo commented 3 years ago

Description: Check the following segment

    stream<BRecord, sql:Error> jsonResultStream = dbClient->query(query);
    // Iterating the returned table.var
    var bRecord = check jsonResultStream.next();
    // Following statement will result in an NPE if if SQL query return empty record
    var value = bRecord.value

As I understood In the above case we should not be able access bRecord.value since bRecord can be ()

Affected Versions: slbeta2

hasithaa commented 3 years ago

Can you attach the stack trace?

hevayo commented 3 years ago

Following is what I get in console log

[2021-07-12 14:13:03,043] SEVERE {b7a.log.crash} - null 
java.lang.NullPointerException
    at io.ballerina.runtime.api.values.BError.<init>(BError.java:37)
    at io.ballerina.runtime.internal.values.ErrorValue.<init>(ErrorValue.java:90)
    at io.ballerina.runtime.internal.values.ErrorValue.<init>(ErrorValue.java:80)
    at io.ballerina.runtime.api.creators.ErrorCreator.createError(ErrorCreator.java:51)
    at io.ballerina.runtime.api.creators.ErrorCreator.createError(ErrorCreator.java:140)
    at io.ballerina.runtime.internal.scheduling.Scheduler.postProcess(Scheduler.java:387)
    at io.ballerina.runtime.internal.scheduling.Scheduler.run(Scheduler.java:343)
    at io.ballerina.runtime.internal.scheduling.Scheduler.runSafely(Scheduler.java:295)
    at java.base/java.lang.Thread.run(Thread.java:834)
pcnfernando commented 3 years ago

Seems to be related to https://github.com/ballerina-platform/ballerina-lang/issues/31464

pcnfernando commented 2 years ago

This results in a compilation error with SwanLake as the resulting stream from the query is restricted to be a bounded stream which includes nil type in the stream's completion.

stream<record {}, error> resultStream =
            mysqlClient->query(`SELECT * FROM Customers`);  //incompatible types: expected 'stream<record {| anydata...; |},error>', found 'stream<record {| anydata...; |},ballerina/sql:1.3.0:Error?>'

Fixed with https://github.com/ballerina-platform/ballerina-lang/pull/31674. Hence closing.

github-actions[bot] commented 2 years ago

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.