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]: NPE in SymbolFactory #41293

Closed
MaryamZi opened this issue Aug 25, 2023 · 2 comments · Fixed by #41665
Closed

[Bug]: NPE in SymbolFactory #41293

MaryamZi opened this issue Aug 25, 2023 · 2 comments · Fixed by #41665
Assignees
Labels
Area/SemanticAPI Semantic API Related Issues #Compiler 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
Milestone

Comments

@MaryamZi
Copy link
Member

Description

$title.

Steps to Reproduce

import ballerina/http;
import ballerina/log;

type Patient record {|
    string name;
    string dob;
    string ssn;
    string address;
    string phone;
    string email;
|};

type ReservationRequest record {|
    record {|
        *Patient;
        string cardNo;
    |} patient;
    string doctor;
    string hospital_id;
    string hospital;
    string appointment_date;
|};

type Doctor record {|
    string name;
    string hospital;
    string category;
    string availability;
    decimal fee;
|};

type Appointment record {|
    int appointmentNumber;
    Doctor doctor;
    Patient patient;
    decimal fee;
    boolean confirmed;
    string hospital;
    string appointmentDate;
|};

type Fee record {|
    string patientName;
    string doctorName;
    string actualFee;
|};

type ReservationStatus record {|
    int appointmentNo;
    string doctorName;
    string patient;
    int actualFee;
    int discount;
    decimal discounted;
    string paymentID;
    string status;
|};

configurable int port = 8290;
configurable string hospitalServicesBackend = "http://localhost:9090";

final http:Client hospitalServicesEP = check initializeHttpClient();

function initializeHttpClient() returns http:Client|error => new (hospitalServicesBackend);

service /healthcare on new http:Listener(port) {
    resource function post categories/[string category]/reserve(ReservationRequest payload) 
            returns ReservationStatus|http:NotFound|http:InternalServerError {
        log:printInfo("Initiating reservation process", specialization = category);
        
        ReservationRequest {
            patient: {cardNo, ...patient},
            doctor, 
            hospital,
            hospital_id,
            appointment_date
        } = payload;

        Appointment|http:ClientError appointment = 
            hospitalServicesEP->/[hospital_id]/categories/[category]/reserve.post({patient, doctor, hospital, appointment_date});
        if appointment !is Appointment {
            log:printError("Appointment reservation failed", appointment);
            if appointment is http:ClientRequestError {
                return <http:NotFound> {body: string `unknown hospital, doctor, or category`};
            }
            return <http:InternalServerError> {body: appointment.message()};
        }

        Fee|http:ClientError fee = hospitalServicesEP->/[hospital_id]/categories/appointments/[appointment.appointmentNumber]/fee;
        if fee !is Fee {
            log:printError("Retrieving fee failed", fee);
            if fee is http:ClientRequestError {
                return <http:NotFound> {body: string `unknown appointment ID`};
            }
            return <http:InternalServerError> {body: fee.message()};
        }

        decimal|error actualFee = decimal:fromString(fee.actualFee);
        if actualFee is error {
            return <http:InternalServerError> {body: "fee retrieval failed"};
        }

        int appointmentNumber = appointment.appointmentNumber;

        ReservationStatus|http:ClientError status = hospitalServicesEP->/healthcare/payments.post( {
            appointmentNumber,
            doctor: appointment.doctor,
            patient,
            fee: actualFee,
            confirmed: false,
            card_number: cardNo
        });
        if status !is ReservationStatus {
            log:printError("Payment failed", status);
            if status is http:ClientRequestError {
                return <http:NotFound> {body: string `unknown appointment ID`};
            }
            return <http:InternalServerError> {body: status.message()};
        }

        log:printInfo("Appointment reservation successful", 
                      name = patient.name, appointmentNumber = appointmentNumber);
        return status;
    }
}
java.lang.NullPointerException
	at io.ballerina.compiler.api.impl.SymbolFactory.getBField(SymbolFactory.java:767)
	at io.ballerina.compiler.api.impl.SymbolFactory.createRecordFieldSymbol(SymbolFactory.java:391)
	at io.ballerina.compiler.api.impl.SymbolFactory.getBCompiledSymbol(SymbolFactory.java:169)
	at io.ballerina.compiler.api.impl.BallerinaSemanticModel.lookupSymbol(BallerinaSemanticModel.java:440)
	at io.ballerina.compiler.api.impl.BallerinaSemanticModel.symbol(BallerinaSemanticModel.java:181)
	at org.ballerinalang.langserver.semantictokens.SemanticTokensVisitor.processSymbols(SemanticTokensVisitor.java:456)
	at org.ballerinalang.langserver.semantictokens.SemanticTokensVisitor.visit(SemanticTokensVisitor.java:191)
	at io.ballerina.compiler.syntax.tree.SimpleNameReferenceNode.accept(SimpleNameReferenceNode.java:41)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visitSyntaxNode(NodeVisitor.java:966)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visit(NodeVisitor.java:151)
	at io.ballerina.compiler.syntax.tree.FieldAccessExpressionNode.accept(FieldAccessExpressionNode.java:49)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visitSyntaxNode(NodeVisitor.java:966)
	at org.ballerinalang.langserver.semantictokens.SemanticTokensVisitor.visit(SemanticTokensVisitor.java:421)
	at io.ballerina.compiler.syntax.tree.NamedArgumentNode.accept(NamedArgumentNode.java:49)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visitSyntaxNode(NodeVisitor.java:966)
	at org.ballerinalang.langserver.semantictokens.SemanticTokensVisitor.visit(SemanticTokensVisitor.java:152)
	at io.ballerina.compiler.syntax.tree.FunctionCallExpressionNode.accept(FunctionCallExpressionNode.java:53)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visitSyntaxNode(NodeVisitor.java:966)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visit(NodeVisitor.java:91)
	at io.ballerina.compiler.syntax.tree.ExpressionStatementNode.accept(ExpressionStatementNode.java:45)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visitSyntaxNode(NodeVisitor.java:966)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visit(NodeVisitor.java:323)
	at io.ballerina.compiler.syntax.tree.FunctionBodyBlockNode.accept(FunctionBodyBlockNode.java:58)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visitSyntaxNode(NodeVisitor.java:966)
	at org.ballerinalang.langserver.semantictokens.SemanticTokensVisitor.visit(SemanticTokensVisitor.java:137)
	at io.ballerina.compiler.syntax.tree.FunctionDefinitionNode.accept(FunctionDefinitionNode.java:66)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visitSyntaxNode(NodeVisitor.java:966)
	at org.ballerinalang.langserver.semantictokens.SemanticTokensVisitor.visit(SemanticTokensVisitor.java:233)
	at io.ballerina.compiler.syntax.tree.ServiceDeclarationNode.accept(ServiceDeclarationNode.java:82)
	at io.ballerina.compiler.syntax.tree.NodeVisitor.visitSyntaxNode(NodeVisitor.java:966)
	at org.ballerinalang.langserver.semantictokens.SemanticTokensVisitor.getSemanticTokens(SemanticTokensVisitor.java:107)
	at org.ballerinalang.langserver.semantictokens.SemanticTokensUtils.getSemanticTokens(SemanticTokensUtils.java:64)
	at org.ballerinalang.langserver.BallerinaTextDocumentService.lambda$semanticTokensFull$16(BallerinaTextDocumentService.java:665)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

Affected Version(s)

2201.7.2

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 MaryamZi added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Area/SemanticAPI Semantic API Related Issues #Compiler labels Aug 25, 2023
@gimantha gimantha assigned nipunayf and unassigned nipunayf Aug 28, 2023
@poorna2152 poorna2152 self-assigned this Nov 1, 2023
@poorna2152
Copy link
Contributor

poorna2152 commented Nov 6, 2023

Minimal code to reproduce the error,

import ballerina/log;

type User record {|
    string name;
|};

type Payload record {|
    record {|
        *User;
        string cardNo;
    |} patient;
|};

function foo(Payload payload) {
    Payload {patient: {...patient}} = payload;
    log:printInfo("Appointment reservation successful", name = patient.name);
}

public function main() {
    Payload request = {
        patient: {name: "jack", cardNo: "1"}
    };
    foo(request);
}

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.

@KavinduZoysa KavinduZoysa added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Dec 21, 2023
@poorna2152 poorna2152 added this to the 2201.9.0 milestone Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/SemanticAPI Semantic API Related Issues #Compiler 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants