ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
137 stars 58 forks source link

Class cast error for data.xmldata where expected type is a recored nested to an open record #6659

Closed prakanth97 closed 1 month ago

prakanth97 commented 3 months ago

Description:

import ballerina/io;
import ballerina/data.xmldata;

public function main() returns error? {
    string xmlStr = string `
    <Data>
        <field2>
            <str2>2</str2>
            <str1>1</str1>
        </field2>
    </Data>
    `;
    record {|
        record {
            string str1;
        } field2;
    |} rec = check xmldata:parseString(xmlStr);
    io:println(rec.field2.str1 is string);
}

This give below runtime error

Running executable

[2024-06-25 17:39:38,961] SEVERE {b7a.log.crash} - class java.lang.Long cannot be cast to class io.ballerina.runtime.api.values.BString (java.lang.Long is in module java.base of loader 'bootstrap'; io.ballerina.runtime.api.values.BString is in unnamed module of loader 'app') 
java.lang.ClassCastException: class java.lang.Long cannot be cast to class io.ballerina.runtime.api.values.BString (java.lang.Long is in module java.base of loader 'bootstrap'; io.ballerina.runtime.api.values.BString is in unnamed module of loader 'app')
        at io.ballerina.runtime.internal.values.MapValueImpl.getStringValue(MapValueImpl.java:156)
        at prakanth.test_xmldata.0.main.main(main.bal:18)
        at prakanth.test_xmldata.0.$_init.$moduleExecute(test_xmldata)
        at prakanth.test_xmldata.0.$_init.$lambda$$moduleExecute$(test_xmldata)
        at io.ballerina.runtime.internal.scheduling.SchedulerItem.execute(SchedulerItem.java:54)
        at io.ballerina.runtime.internal.scheduling.Scheduler.run(Scheduler.java:320)
        at io.ballerina.runtime.internal.scheduling.Scheduler.runSafely(Scheduler.java:287)
        at java.base/java.lang.Thread.run(Thread.java:833)

Steps to reproduce:

Affected Versions:

OS, DB, other environment details and versions:

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

github-actions[bot] commented 1 month 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.