- 2201.12.11 (Swan Lake Update 12)
- 2201.12.10 (Swan Lake Update 12)
- 2201.12.9 (Swan Lake Update 12)
- 2201.12.8 (Swan Lake Update 12)
- 2201.12.7 (Swan Lake Update 12)
- 2201.12.6 (Swan Lake Update 12)
- 2201.12.5 (Swan Lake Update 12)
- 2201.12.4 (Swan Lake Update 12)
- 2201.12.3 (Swan Lake Update 12)
- 2201.12.2 (Swan Lake Update 12)
- 2201.12.1 (Swan Lake Update 12)
- 2201.12.0 (Swan Lake Update 12)
- 2201.8.10 (Swan Lake Update 8)
- 2201.8.9 (Swan Lake Update 8)
- 2201.8.8 (Swan Lake Update 8)
- 2201.8.7 (Swan Lake Update 8)
- 2201.8.6 (Swan Lake Update 8)
- 2201.8.5 (Swan Lake Update 8)
- 2201.8.4 (Swan Lake Update 8)
- 2201.8.3 (Swan Lake Update 8)
- 2201.8.2 (Swan Lake Update 8)
- 2201.8.1 (Swan Lake Update 8)
- 2201.8.0 (Swan Lake Update 8)
- 1.2.64
- 1.2.63
- 1.2.62
- 1.2.61
- 1.2.60
- 1.2.59
- 1.2.58
- 1.2.57
- 1.2.56
- 1.2.55
- 1.2.54
- 1.2.53
- 1.2.52
- 1.2.51
- 1.2.50
- 1.2.49
- 1.2.48
- 1.2.47
- 1.2.46
- 1.2.45
- 1.2.44
- 1.2.43
- 1.2.42
- 1.2.41
- 1.2.40
- 1.2.39
- 1.2.38
- 1.2.37
- 1.2.36
- 1.2.35
- 1.2.34
- 1.2.33
- 1.2.32
- 1.2.31
- 1.2.30
- 1.2.29
- 1.2.28
- 1.2.27
- 1.2.26
- 1.2.25
- 1.2.24
- 1.2.23
- 1.2.22
- 1.2.21
- 1.2.20
- 1.2.19
- 1.2.18
- 1.2.17
- 1.2.16
- 1.2.15
- 1.2.14
- 1.2.13
- 1.2.12
- 1.2.11
- 1.2.10
- 1.2.9
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
Overview of Ballerina Swan Lake 2201.6.0
2201.6.0 (Swan Lake Update 6) is the sixth update release of Ballerina Swan Lake, and it includes a new set of features and significant improvements to the compiler, runtime, standard library, and developer tooling. It is based on the 2022R4 version of the Language Specification.
Update Ballerina
Update your current Ballerina installation directly to 2201.6.0 using the Ballerina Update Tool as follows.
- Run
bal updateto get the latest version of the Update Tool. - Run
bal dist updateto update to this latest distribution.
Install Ballerina
If you have not installed Ballerina, download the installers to install.
Language updates
New features
New lang library functions
New lang.int:avg() function
-
Introduced the
lang.int:avg()function, which returns the average of its integer arguments.import ballerina/io; public function main() { io:println(int:avg(10, 20, 30, 40)); // 25.0 }
New lang.float:avg() function
-
Introduced the
lang.float:avg()function, which returns the average of its float arguments.import ballerina/io; public function main() { io:println(float:avg(2, 2)); // 2.0 }
New lang.decimal:avg() function
-
Introduced the
lang.decimal:avg()function, which returns the average of its decimal arguments.import ballerina/io; public function main() { io:println(decimal:avg(10, 20, 30, 40)); // 25.0 }
New lang.boolean:some() function
-
Introduced the
lang.boolean:some()function, which returns true if one or more of its arguments aretrue, andfalseotherwise.import ballerina/io; public function main() { io:println(boolean:some(true, false)); // true io:println(boolean:some(false, false)); // false }
New lang.boolean:every() function
-
Introduced the
lang.boolean:every()function, which returnstrueif all of its arguments are true, andfalseotherwise.import ballerina/io; public function main() { io:println(boolean:every(true, false)); // false io:println(boolean:every(true, true)); // true }
New lang.value:count() function
-
Introduced the
lang.value:count()function, which returns the number of arguments.import ballerina/io; import ballerina/lang.value; public function main() { io:println(value:count(1, 2, 3)); // 3 }
New lang.value:first() function
-
Introduced the
lang.value:first()function, which returns the first argument.import ballerina/io; import ballerina/lang.value; public function main() { io:println(value:first(1, 2, 3)); // 1 }
New lang.value:last() function
-
Introduced the
lang.value:last()function, which returns the last argument.import ballerina/io; import ballerina/lang.value; public function main() { io:println(value:last(1, 2, 3)); // 3 }
Bug fixes
To view other bug fixes, see the GitHub milestone for 2201.6.0 (Swan Lake).
Runtime updates
New features
New Runtime Java APIs
-
Introduced the
getInitMethod()API in theio.ballerina.runtime.api.types.ObjectTypeclass to get the method type of the initializer method of Ballerina objects.MethodType getInitMethod();
Deprecations
Deprecations in Runtime Java APIs
-
Deprecated the following APIs in the
io.ballerina.runtime.apipackage and marked for removal in a future release.Runtime API Java class getCurrentRuntime()io.ballerina.runtime.api.RuntimecreateDecimalValue(String, DecimalValueKind)io.ballerina.runtime.api.creators.ValueCreatorcreateStreamingJsonValue(JsonDataSource)io.ballerina.runtime.api.creators.ValueCreatorconvertToJson(Object, List<TypeValuePair>)io.ballerina.runtime.api.utils.JsonUtilsgetStringValue(Object, BLink)io.ballerina.runtime.api.utils.StringUtilsgetExpressionStringValue(Object, BLink)io.ballerina.runtime.api.utils.StringUtilsparseExpressionStringValue(String, BLink)io.ballerina.runtime.api.utils.StringUtilsgetValueKind()io.ballerina.runtime.api.values.BDecimalgetStrand()io.ballerina.runtime.api.values.BFuturecall(Strand, String, Object...)io.ballerina.runtime.api.values.BObjectstart(Strand, String, Object...)io.ballerina.runtime.api.values.BObjectgetRegExpDisjunction()io.ballerina.runtime.api.values.BRegexpValueinstantiate(Strand)io.ballerina.runtime.api.values.BTypedescinstantiate(Strand, BInitialValueEntry[])io.ballerina.runtime.api.values.BTypedesc
Bug fixes
To view bug fixes, see the GitHub milestone for 2201.6.0 (Swan Lake).
Standard library updates
New features
constraint package
- Introduced the
@constriant:Dateannotation to validate date record structures. - Allowed constraint annotations on subtypes.
http package
- Added constraint validation support for
query,path, andheaderparameters. - Exposed the
http:Requestobject in the response interceptors as a remote method parameter. - Added finite type support for
query,path, andheaderparameters.
graphql package
- Added support for GraphQL field interceptors.
- Added support for GraphQL interceptor configurations.
- Added support to access subfields of a GraphQL field from the
graphql:Fieldobject.
persist package
- Added support for the
in-memorydata store. - Added support for the
google-sheetsdata store. This is currently an experimental feature and its behavior may be subject to change in future releases. - Added support for defining enums and adding
enumfields to the data model.
edi package
- Introduced the
edimodule to convert EDI to JSON and vice versa based on a given schema.
toml package
- Introduced the pre-release version of the
tomlmodule to convert a TOML configuration file tomap<json>and vice versa.
yaml package
- Introduced the pre-release version of the
yamlmodule to convert a YAML configuration file to JSON and vice versa.
Deprecations
stan package
- Deprecated the
stanpackage.For NATS-enabled applications requiring persistence, it is recommended to use
JetStreamprovided by theballerinax/natslibrary, including the new NATS JetStream client and the NATS JetStream listener.
serdes package
- Deprecated the
serdespackage.
Improvements
persist package
- Renamed the error types as follows.
InvalidKeyErrortoNotFoundErrorDuplicateKeyErrortoAlreadyExistsErrorForeignKeyConstraintViolationErrortoForeignKeyViolationError
- Removed the
FieldDoesNotExistErrorerror type as theNotFoundErrorerror type can be used instead. - Marked the generated client object as
isolated. - Added support for transactions in the
mysqldata store.
http package
-
Allowed a single interceptor service object to be configured as the interceptor pipeline.
-
Allowed the subtypes of one of
string,int,float,boolean, ordecimalas path parameters. -
Added support for
http:InterceptableServiceto enable engaging service-level interceptors and deprecated the usage of interceptors in thehttp:HttpServiceConfig.For example, consider the following implementation of the
http:InterceptableService.import ballerina/http; service http:InterceptableService / on new http:Listener(9090) { public function createInterceptors() returns RequestInterceptor { return new RequestInterceptor(); } resource function get user() returns string { return "John, Doe"; } }
Bug fixes
To view bug fixes, see the GitHub milestone for 2201.6.0 (Swan Lake).
Developer tools updates
New features
Persist Tool
- Added support for the
in-memorydata store. This is set as the default data store. - Added support for the
google-sheetsdata store. This is currently an experimental feature and its behavior may be subject to change in future releases. - Added the
persist migratecommand to generate migration scripts for data model changes in themysqldata store. The support for migrations is currently an experimental feature and its behavior may be subject to change in future releases.
Language Server
- Added inlay hint support for function call expressions and method call expressions to provide information about parameters.
Deprecations
CLI Commands
Deprecation of bal init
- Deprecated the
bal initcommand. It will be removed in a future version. Thebal new .command can be used instead.
Improvements
Test Framework
- Added support for excluding source files from code coverage.
Persist Tool
- Added support for additional DB configurations in the generated client objects for the
mysqldata store. - Changed the Ballerina
byte[]type mapping toLONGBLOBin the generated SQL script file.
Language Server
- Removed service template initialization from the lightweight mode.
- Improved the completion support and signature help for client resource access actions.
- Improved the main function completion item.
- Improved completions in the named argument context.
- Added support to rename parameter documentation for record fields and required parameters.
OpenAPI Tool
- Added support for regular expression templates (i.e., the
patternproperty) defined on OpenAPIstringtypes in the Ballerina client and service generation. With this support, the aforementioned Regex templates will be represented asballerina/constraintmodule annotations in the generated code. This support applies to Regex patterns that satisfy the Ballerina regular expression grammar. - Added support for OpenAPI enums in the client and service generation.
- Added support for query parameters with referenced schema in the Ballerina service generation.
- Added support for header parameters with referenced schema in the Ballerina service generation.
- Added support for
integer,float,decimal, andbooleanheader parameter types in the Ballerina service generation.
Architecture Model Generator
- Added a new language server extension to retrieve Ballerina persist models.
- Added support to retrieve dependencies of the main function entry points.
CLI commands
Support for providing paths with bal new
- Added support to provide a directory path with the
bal newcommand to create a package in a specific directory (e.g.,bal new <package-path>).
Bug fixes
To view bug fixes, see the GitHub milestone for 2201.6.0 (Swan Lake) of the repositories below.
Ballerina packages updates
Bug fixes
To view bug fixes, see the GitHub milestone for 2201.6.0 (Swan Lake).
Backward-incompatible changes
-
selfof an object is now implicitly final and cannot be assigned to.class Counter { private int i = 0; function updateSelf() { self = new; // Compilation error now. } function increment() { lock { self.i += 1; } } }This also allows using
selfof an object that is a subtype ofreadonlyorisolated object {}as a captured variable within anisolatedanonymous function.isolated class Filter { final string[] & readonly words; private int length; isolated function init(string[] & readonly words, int length) { self.words = words; self.length = length; } isolated function setLength(int length) { lock { self.length = length; } } isolated function getCount() returns int => self.words.filter( // Allowed now. word => word.length() == self.length).length(); } -
Fixed a bug that allowed assigning
nilto a record field with member access expressions when there are no fields of optional types. This previously resulted in a runtime panic if the value wasnil.type Employee record {| string id; string name; |}; public function main() { Employee employee = { name: "Jo", id: "E12321" }; string key = "name"; employee[key] = (); // Compilation error now. map<string> data = { name: "Jo Doe", dept: "IT" }; foreach string mkey in employee.keys() { // `data[key]` will be nil if the key is not present in `data`. // E.g., `data[key]` is nil when `key` is `name`. employee[mkey] = data[mkey]; // Compilation error now. } } -
Fixed a bug with the XML parser error messages that showed dependency information. The error message prefix
failed to create xmlis now changed tofailed to parse xmlto have a single prefix for all the XML-parsing error messages.For example, consider the content below of the
invalid_xml.txtfile.<!-- comments cannot have -- in it -->When the following Ballerina code is run,
import ballerina/io; public function main() returns error? { xml readResult = check io:fileReadXml("invalid_xml.txt"); }it gives the error below.
error: failed to parse xml: String '--' not allowed in comment (missing '>'?) at [row,col {unknown-source}]: [1,4] -
The
Environment,Future, andRuntimeclasses in theio.ballerina.runtime.apipackage, are refactored to abstract classes. Creating an instance of those classes is incorrect. -
A
typedescvalue (returned by evaluating thetypeofexpression on a result of thevalue:cloneWithTypeandvalue:fromJsonWithTypefunctions) is changed to give the correct type-reference type.import ballerina/io; type IntArray int[]; public function main() returns error? { float[] arr = [1.0, 2.0]; IntArray result = check arr.cloneWithType(); io:println(typeof result); // Prints 'typedesc IntArray'. }