From 1afcfca17fbe92813a2ab5588be316512a121948 Mon Sep 17 00:00:00 2001 From: niveathika Date: Thu, 23 Dec 2021 00:13:51 +0530 Subject: [PATCH 1/6] Fix plugin crash when variable is passed for `Options` --- changelog.md | 7 +++- .../mssql/compiler/CompilerPluginTest.java | 13 ++++++++ .../diagnostics/sample4/Ballerina.toml | 4 +++ .../resources/diagnostics/sample4/main.bal | 32 +++++++++++++++++++ .../stdlib/mssql/compiler/Utils.java | 9 +++--- .../analyzer/InitializerParamAnalyzer.java | 6 ++-- 6 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 compiler-plugin-tests/src/test/resources/diagnostics/sample4/Ballerina.toml create mode 100644 compiler-plugin-tests/src/test/resources/diagnostics/sample4/main.bal diff --git a/changelog.md b/changelog.md index 0884f6ac..be70df9a 100644 --- a/changelog.md +++ b/changelog.md @@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- [Add tooling support](https://github.com/ballerina-platform/ballerina-standard-library/issues/2282) ### Changed +- [Fix Compiler plugin crash when variable is passed for `sql:ConnectionPool` and `mssql:Options`](https://github.com/ballerina-platform/ballerina-standard-library/issues/2536) + +## [1.2.0] - 2021-12-13 + +### Added +- [Add tooling support](https://github.com/ballerina-platform/ballerina-standard-library/issues/2282) ## [1.1.0] - 2021-11-20 diff --git a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/mssql/compiler/CompilerPluginTest.java b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/mssql/compiler/CompilerPluginTest.java index 8acf515b..3e172ef6 100644 --- a/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/mssql/compiler/CompilerPluginTest.java +++ b/compiler-plugin-tests/src/test/java/io/ballerina/stdlib/mssql/compiler/CompilerPluginTest.java @@ -135,4 +135,17 @@ public void testMSSQLOptionRecord() { }); } + @Test + public void testOptionsWithVariables() { + Package currentPackage = loadPackage("sample4"); + PackageCompilation compilation = currentPackage.getCompilation(); + DiagnosticResult diagnosticResult = compilation.diagnosticResult(); + List diagnosticErrorStream = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + long availableErrors = diagnosticErrorStream.size(); + + Assert.assertEquals(availableErrors, 0); + } + } diff --git a/compiler-plugin-tests/src/test/resources/diagnostics/sample4/Ballerina.toml b/compiler-plugin-tests/src/test/resources/diagnostics/sample4/Ballerina.toml new file mode 100644 index 00000000..e7d690d1 --- /dev/null +++ b/compiler-plugin-tests/src/test/resources/diagnostics/sample4/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "mssql_test" +name = "sample4" +version = "0.1.0" diff --git a/compiler-plugin-tests/src/test/resources/diagnostics/sample4/main.bal b/compiler-plugin-tests/src/test/resources/diagnostics/sample4/main.bal new file mode 100644 index 00000000..caaa4689 --- /dev/null +++ b/compiler-plugin-tests/src/test/resources/diagnostics/sample4/main.bal @@ -0,0 +1,32 @@ +// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +// +// WSO2 Inc. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerinax/mssql; + +public function main() { + + decimal loginTimeout = 5; + decimal loginTimeoutInvalid = -5; + + mssql:Options options1 = { + loginTimeout: loginTimeout + }; + + mssql:Options options2 = { + loginTimeout: loginTimeoutInvalid + }; + +} diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/mssql/compiler/Utils.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/mssql/compiler/Utils.java index 6301ad62..2a2e574a 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/mssql/compiler/Utils.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/mssql/compiler/Utils.java @@ -83,7 +83,7 @@ public static void validateOptions(SyntaxNodeAnalysisContext ctx, MappingConstru switch (name) { case Constants.Options.LOGIN_TIMEOUT: case Constants.Options.SOCKET_TIMEOUT: - float fieldVal = Float.parseFloat(getTerminalNodeValue(valueNode)); + float fieldVal = Float.parseFloat(getTerminalNodeValue(valueNode, "0")); if (fieldVal < 0) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MSSQL_101.getCode(), MSSQL_101.getMessage(), MSSQL_101.getSeverity()); @@ -92,7 +92,7 @@ public static void validateOptions(SyntaxNodeAnalysisContext ctx, MappingConstru } break; case Constants.Options.QUERY_TIMEOUT: - float queryTimeout = Float.parseFloat(getTerminalNodeValue(valueNode)); + float queryTimeout = Float.parseFloat(getTerminalNodeValue(valueNode, "0")); if (queryTimeout < -1) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(MSSQL_102.getCode(), MSSQL_102.getMessage(), MSSQL_102.getSeverity()); @@ -107,8 +107,8 @@ public static void validateOptions(SyntaxNodeAnalysisContext ctx, MappingConstru } } - public static String getTerminalNodeValue(Node valueNode) { - String value = ""; + public static String getTerminalNodeValue(Node valueNode, String defaultValue) { + String value = defaultValue; if (valueNode instanceof BasicLiteralNode) { value = ((BasicLiteralNode) valueNode).literalToken().text(); } else if (valueNode instanceof UnaryExpressionNode) { @@ -116,6 +116,7 @@ public static String getTerminalNodeValue(Node valueNode) { value = unaryExpressionNode.unaryOperator() + ((BasicLiteralNode) unaryExpressionNode.expression()).literalToken().text(); } + // Currently, we cannot process values from variables, this needs code flow analysis return value.replaceAll(UNNECESSARY_CHARS_REGEX, ""); } } diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/mssql/compiler/analyzer/InitializerParamAnalyzer.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/mssql/compiler/analyzer/InitializerParamAnalyzer.java index 99b34c26..4f7ecaea 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/mssql/compiler/analyzer/InitializerParamAnalyzer.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/mssql/compiler/analyzer/InitializerParamAnalyzer.java @@ -115,7 +115,7 @@ private void validateConnectionPool(SyntaxNodeAnalysisContext ctx, MappingConstr ExpressionNode valueNode = ((SpecificFieldNode) field).valueExpr().get(); switch (name) { case Constants.ConnectionPool.MAX_OPEN_CONNECTIONS: - int maxOpenConnections = Integer.parseInt(getTerminalNodeValue(valueNode)); + int maxOpenConnections = Integer.parseInt(getTerminalNodeValue(valueNode, "1")); if (maxOpenConnections < 1) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(SQL_101.getCode(), SQL_101.getMessage(), SQL_101.getSeverity()); @@ -126,7 +126,7 @@ private void validateConnectionPool(SyntaxNodeAnalysisContext ctx, MappingConstr } break; case Constants.ConnectionPool.MIN_IDLE_CONNECTIONS: - int minIdleConnection = Integer.parseInt(getTerminalNodeValue(valueNode)); + int minIdleConnection = Integer.parseInt(getTerminalNodeValue(valueNode, "0")); if (minIdleConnection < 0) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(SQL_102.getCode(), SQL_102.getMessage(), SQL_102.getSeverity()); @@ -136,7 +136,7 @@ private void validateConnectionPool(SyntaxNodeAnalysisContext ctx, MappingConstr } break; case Constants.ConnectionPool.MAX_CONNECTION_LIFE_TIME: - float maxConnectionTime = Float.parseFloat(getTerminalNodeValue(valueNode)); + float maxConnectionTime = Float.parseFloat(getTerminalNodeValue(valueNode, "30")); if (maxConnectionTime < 30) { DiagnosticInfo diagnosticInfo = new DiagnosticInfo(SQL_103.getCode(), SQL_103.getMessage(), SQL_103.getSeverity()); From f1f767403644ab4fb38dbb511c4c2ea7018291cf Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Tue, 1 Feb 2022 13:49:56 +0530 Subject: [PATCH 2/6] Update patch version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 696d4488..a4bcb3f2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=io.ballerina.stdlib -version=1.2.0 +version=1.2.1 puppycrawlCheckstyleVersion=8.18 msSQLDriverVersion=9.2.0.jre11 From f735cf35a5ba55ee8ac345358df8f43525d23d1e Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Tue, 1 Feb 2022 13:57:38 +0530 Subject: [PATCH 3/6] Update SQL version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a4bcb3f2..6184ee32 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ ballerinaGradlePluginVersion=0.14.1 ballerinaLangVersion=2.0.0-beta.6 -stdlibSqlVersion=1.2.0 +stdlibSqlVersion=1.2.1-20220201-131400-11b4211 stdlibIoVersion=1.1.0 stdlibRegexVersion=1.1.0 From 63bdc4b0a62c58c401ed0750d34fdbf734478481 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Tue, 1 Feb 2022 13:58:23 +0530 Subject: [PATCH 4/6] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 6 +++--- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 51c3df1e..861fe6ed 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerinax" name = "mssql" -version = "1.2.0" +version = "1.2.1" authors = ["Ballerina"] keywords = ["database", "client", "network", "SQL", "RDBMS", "SQLServer", "MSSQL"] repository = "https://github.com/ballerina-platform/module-ballerinax-mssql" @@ -9,10 +9,10 @@ license = ["Apache-2.0"] distribution = "slbeta6" [[platform.java11.dependency]] -path = "../native/build/libs/mssql-native-1.2.0.jar" +path = "../native/build/libs/mssql-native-1.2.1.jar" [[platform.java11.dependency]] -path = "./lib/sql-native-1.2.0.jar" +path = "./lib/sql-native-1.2.1-20220201-131400-11b4211.jar" [[platform.java11.dependency]] path = "./lib/mssql-jdbc-9.2.0.jre11.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 2ac299e7..4988e7f4 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "mssql-compiler-plugin" class = "io.ballerina.stdlib.mssql.compiler.MSSQLCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/mssql-compiler-plugin-1.2.0.jar" +path = "../compiler-plugin/build/libs/mssql-compiler-plugin-1.2.1.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index f3fd0bbc..0c41029e 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -130,7 +130,7 @@ dependencies = [ [[package]] org = "ballerina" name = "sql" -version = "1.2.0" +version = "1.2.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -167,7 +167,7 @@ modules = [ [[package]] org = "ballerinax" name = "mssql" -version = "1.2.0" +version = "1.2.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "file"}, From ba61e9dc5cf78ebbd8e4fca1a5af9d2f1dd2d6a0 Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Thu, 3 Feb 2022 12:53:01 +0530 Subject: [PATCH 5/6] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 861fe6ed..3cc95008 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -12,7 +12,7 @@ distribution = "slbeta6" path = "../native/build/libs/mssql-native-1.2.1.jar" [[platform.java11.dependency]] -path = "./lib/sql-native-1.2.1-20220201-131400-11b4211.jar" +path = "./lib/sql-native-1.2.1.jar" [[platform.java11.dependency]] path = "./lib/mssql-jdbc-9.2.0.jre11.jar" From 6bbb5cb2c9bc01f1042923f17eca0c44cab04bbd Mon Sep 17 00:00:00 2001 From: Kaneel Dias Date: Thu, 3 Feb 2022 12:53:59 +0530 Subject: [PATCH 6/6] Update SQL version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 6184ee32..67c84a40 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ ballerinaGradlePluginVersion=0.14.1 ballerinaLangVersion=2.0.0-beta.6 -stdlibSqlVersion=1.2.1-20220201-131400-11b4211 +stdlibSqlVersion=1.2.1 stdlibIoVersion=1.1.0 stdlibRegexVersion=1.1.0