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

NullPointerException when retrieving record with default value #2985

Closed
kaneeldias opened this issue Jun 8, 2022 · 1 comment · Fixed by ballerina-platform/module-ballerina-sql#533
Assignees
Labels
module/java.jdbc Priority/High Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/DIU Data, IO, and Util packages related issues Type/Bug
Milestone

Comments

@kaneeldias
Copy link
Contributor

A NullPointerException is thrown when retrieving a record which has a default value from a database table when that field itself is not retrieved.

import ballerina/sql;
import ballerinax/java.jdbc;
import ballerina/test;

type Employee record {|
    readonly int employee_id;
    string name;
    boolean active = false;
|};

@test:Config
function testRecordDefaultValue() returns error?{
    Employee e = {
        employee_id: 1, 
        name: "John"
    };
        
    // In this case, the default field "active" is created correctly
    test:assertEquals(e.active, false, "Default value of boolean field is not set correctly");


    jdbc:Client dbClient = check new ("jdbc:h2:./db/database", "root", "root");
    sql:ParameterizedQuery query = `select employee_id, name from employee`;
    stream<Employee, error?> employeeStream =  dbClient->query(query);
    check from var item in employeeStream
    do {
        // When the record is created from database query, the default field "active" is NOT set and result in 
        // java.lang.NullPointerException
       test:assertEquals(item.active, false, "Default value of boolean field is not set correctly");
    };
}
@github-actions
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.

@kaneeldias kaneeldias added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Jun 16, 2022
@niveathika niveathika added this to the 2201.2.0 milestone Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/java.jdbc Priority/High Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/DIU Data, IO, and Util packages related issues Type/Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants