From b2519840b0ccf1f084767ef2609daf7edd1bea05 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 20 Aug 2024 13:34:58 +0530 Subject: [PATCH] Fix CCE in arrays with refered types --- ballerina/tests/fromXml_test.bal | 23 +++++++++++++++++++ .../lib/data/xmldata/xml/XmlParser.java | 5 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ballerina/tests/fromXml_test.bal b/ballerina/tests/fromXml_test.bal index 8159c92..f8f63ed 100644 --- a/ballerina/tests/fromXml_test.bal +++ b/ballerina/tests/fromXml_test.bal @@ -3585,3 +3585,26 @@ isolated function testDuplicateField() { test:assertTrue(err4 is Error); test:assertEquals(( err4).message(), "duplicate field 'name'"); } + +type Ports record {| + PortContent[] port; +|}; + +@Namespace { + prefix: "ns1", + uri: "example1.com" +} +type PortContent record {| + string \#content; +|}; + +@test:Config +isolated function testTypeRefArray() { + string s = string ` + + 1 + 1 + `; + Ports|error rec = parseString(s); + test:assertEquals(rec, {"port":[{"#content":"1"},{"#content":"1"}]}); +} diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java index 8f36c4f..98a5a72 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java @@ -357,9 +357,10 @@ private void convertTextAndUpdateCurrentNode(BMap currentNode, @SuppressWarnings("unchecked") private void addTextToCurrentNodeIfExpTypeIsArray(ArrayType fieldType, BString bFieldName, BString bText, XmlParserData xmlParserData) { - int elementTypeTag = TypeUtils.getReferredType(fieldType.getElementType()).getTag(); + Type referredType = TypeUtils.getReferredType(fieldType.getElementType()); + int elementTypeTag = referredType.getTag(); switch (elementTypeTag) { - case TypeTags.RECORD_TYPE_TAG -> handleContentFieldInRecordType((RecordType) fieldType.getElementType(), + case TypeTags.RECORD_TYPE_TAG -> handleContentFieldInRecordType((RecordType) referredType, bText, xmlParserData); case TypeTags.ANYDATA_TAG, TypeTags.JSON_TAG -> { BArray tempArr = (BArray) ((BMap) xmlParserData.nodesStack.peek()).get(bFieldName);