From 2e3ad809b1a38420302032087f7ce961867edcdd Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Tue, 14 May 2024 10:50:58 +0530 Subject: [PATCH 1/7] Remove org.apache.commons.lang3 usage from bvm --- .../io/ballerina/runtime/internal/StateMachine.java | 4 ++-- .../runtime/internal/launch/LaunchUtils.java | 11 +++++++++-- bvm/ballerina-runtime/src/main/java/module-info.java | 1 - 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/StateMachine.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/StateMachine.java index 2babe905b4d2..c605927b1e28 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/StateMachine.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/StateMachine.java @@ -18,10 +18,10 @@ package io.ballerina.runtime.internal; +import io.ballerina.identifier.Utils; import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BError; -import org.apache.commons.lang3.StringEscapeUtils; import java.io.IOException; import java.io.Reader; @@ -707,7 +707,7 @@ private void reset(StateMachine sm) { } private char extractUnicodeChar(StateMachine sm) { - return StringEscapeUtils.unescapeJava("\\u" + sm.hexBuilder).charAt(0); + return Utils.unescapeJava("\\u" + sm.hexBuilder).charAt(0); } } diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java index 733a5c065ef2..5a1e4df3800c 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java @@ -32,7 +32,6 @@ import io.ballerina.runtime.internal.diagnostics.RuntimeDiagnosticLog; import io.ballerina.runtime.internal.troubleshoot.StrandDump; import io.ballerina.runtime.internal.util.RuntimeUtils; -import org.apache.commons.lang3.ArrayUtils; import sun.misc.Signal; import java.io.File; @@ -94,13 +93,21 @@ public static void stopListeners(boolean isService) { listeners.forEach(listener -> listener.afterRunProgram(isService)); } + public static VariableKey[] mergeKeys(VariableKey[] keyArray1, VariableKey[] keyArray2){ + VariableKey[] mergedKeyArray = new VariableKey[keyArray1.length + keyArray2.length]; + System.arraycopy(keyArray1, 0, mergedKeyArray, 0, keyArray1.length); + System.arraycopy(keyArray2, 0, mergedKeyArray, keyArray1.length, keyArray2.length); + + return mergedKeyArray; + } + public static void addModuleConfigData(Map configurationData, Module m, VariableKey[] variableKeys) { VariableKey[] keys = configurationData.put(m, variableKeys); if (keys == null) { return; } - configurationData.put(m, ArrayUtils.addAll(keys, variableKeys)); + configurationData.put(m, mergeKeys(keys, variableKeys)); } public static void initConfigurableVariables(Module rootModule, Map configurationData, diff --git a/bvm/ballerina-runtime/src/main/java/module-info.java b/bvm/ballerina-runtime/src/main/java/module-info.java index 857d248a3977..f34060732a90 100644 --- a/bvm/ballerina-runtime/src/main/java/module-info.java +++ b/bvm/ballerina-runtime/src/main/java/module-info.java @@ -15,7 +15,6 @@ requires transactions.jta; requires java.transaction; requires java.naming; - requires org.apache.commons.lang3; requires io.ballerina.identifier; requires jdk.unsupported; From a1158e817ff12ca8dceb117cf5b0bc00ab521246 Mon Sep 17 00:00:00 2001 From: ravinperera00 <62183347+ravinperera00@users.noreply.github.com> Date: Tue, 14 May 2024 15:11:48 +0530 Subject: [PATCH 2/7] Fix style issue with mergeKeys method Co-authored-by: Gabilan Ganeshwaran --- .../java/io/ballerina/runtime/internal/launch/LaunchUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java index 5a1e4df3800c..e83eb70a7eb4 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java @@ -93,7 +93,7 @@ public static void stopListeners(boolean isService) { listeners.forEach(listener -> listener.afterRunProgram(isService)); } - public static VariableKey[] mergeKeys(VariableKey[] keyArray1, VariableKey[] keyArray2){ + public static VariableKey[] mergeKeys(VariableKey[] keyArray1, VariableKey[] keyArray2) { VariableKey[] mergedKeyArray = new VariableKey[keyArray1.length + keyArray2.length]; System.arraycopy(keyArray1, 0, mergedKeyArray, 0, keyArray1.length); System.arraycopy(keyArray2, 0, mergedKeyArray, keyArray1.length, keyArray2.length); From a79e88aed4176b1235a42478cf9f983015fd7272 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Tue, 14 May 2024 21:47:21 +0530 Subject: [PATCH 3/7] Add null checks and refactor addModuleConfigData - Check for null keyArrays passed into mergeKeys method - Remove repeated use of put method in addModuleConfigData to improve performance --- .../runtime/internal/launch/LaunchUtils.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java index e83eb70a7eb4..2dd3e491aa90 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java @@ -93,7 +93,16 @@ public static void stopListeners(boolean isService) { listeners.forEach(listener -> listener.afterRunProgram(isService)); } - public static VariableKey[] mergeKeys(VariableKey[] keyArray1, VariableKey[] keyArray2) { + private static VariableKey[] mergeKeys(VariableKey[] keyArray1, VariableKey[] keyArray2) { + + if (keyArray1 == null) { + return keyArray2.clone(); + } + + if (keyArray2 == null) { + return keyArray1.clone(); + } + VariableKey[] mergedKeyArray = new VariableKey[keyArray1.length + keyArray2.length]; System.arraycopy(keyArray1, 0, mergedKeyArray, 0, keyArray1.length); System.arraycopy(keyArray2, 0, mergedKeyArray, keyArray1.length, keyArray2.length); @@ -103,11 +112,7 @@ public static VariableKey[] mergeKeys(VariableKey[] keyArray1, VariableKey[] key public static void addModuleConfigData(Map configurationData, Module m, VariableKey[] variableKeys) { - VariableKey[] keys = configurationData.put(m, variableKeys); - if (keys == null) { - return; - } - configurationData.put(m, mergeKeys(keys, variableKeys)); + configurationData.put(m, mergeKeys(configurationData.get(m), variableKeys)); } public static void initConfigurableVariables(Module rootModule, Map configurationData, From fcf58c66a727e6b2b1676f8409bd11d05f63a8b7 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Wed, 15 May 2024 10:40:31 +0530 Subject: [PATCH 4/7] Add missing null check The clone method fails when two null arrays are passed to the mergeKeys method. A check was added to handle this case. --- .../io/ballerina/runtime/internal/launch/LaunchUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java index 2dd3e491aa90..f92f2bfe7951 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java @@ -95,6 +95,10 @@ public static void stopListeners(boolean isService) { private static VariableKey[] mergeKeys(VariableKey[] keyArray1, VariableKey[] keyArray2) { + if (keyArray1 == null && keyArray2 == null) { + return null; + } + if (keyArray1 == null) { return keyArray2.clone(); } From 804282a0b98fc943ac5f0c0b44e4bf6b1aa886f2 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Fri, 17 May 2024 11:14:09 +0530 Subject: [PATCH 5/7] Remove null check on both args in mergeKeys method --- .../io/ballerina/runtime/internal/launch/LaunchUtils.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java index a190d1d4dee8..87e65e37bbda 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java @@ -95,10 +95,6 @@ public static void stopListeners(boolean isService) { private static VariableKey[] mergeKeys(VariableKey[] keyArray1, VariableKey[] keyArray2) { - if (keyArray1 == null && keyArray2 == null) { - return null; - } - if (keyArray1 == null) { return keyArray2.clone(); } From a49725cd45e7f79feeb87bc9233c2aa4fcf5ac3b Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Fri, 17 May 2024 16:22:08 +0530 Subject: [PATCH 6/7] Remove mergeKeys and refactor addModuleConfigData - The mergeKeys method was not reused within the codebase and therefore was not needed as a seperate private method. - Thus, the merging functionality was moved to the addModuleConfigData method. --- .../runtime/internal/launch/LaunchUtils.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java index 87e65e37bbda..5bf84063d1fc 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java @@ -93,26 +93,21 @@ public static void stopListeners(boolean isService) { listeners.forEach(listener -> listener.afterRunProgram(isService)); } - private static VariableKey[] mergeKeys(VariableKey[] keyArray1, VariableKey[] keyArray2) { + public static void addModuleConfigData(Map configurationData, Module m, + VariableKey[] variableKeys) { - if (keyArray1 == null) { - return keyArray2.clone(); - } + VariableKey[] currKeys = configurationData.get(m); + VariableKey[] mergedKeyArray; - if (keyArray2 == null) { - return keyArray1.clone(); + if (currKeys == null) { + mergedKeyArray = variableKeys; + } else { + mergedKeyArray = new VariableKey[currKeys.length + variableKeys.length]; + System.arraycopy(currKeys, 0, mergedKeyArray, 0, currKeys.length); + System.arraycopy(variableKeys, 0, mergedKeyArray, currKeys.length, variableKeys.length); } - VariableKey[] mergedKeyArray = new VariableKey[keyArray1.length + keyArray2.length]; - System.arraycopy(keyArray1, 0, mergedKeyArray, 0, keyArray1.length); - System.arraycopy(keyArray2, 0, mergedKeyArray, keyArray1.length, keyArray2.length); - - return mergedKeyArray; - } - - public static void addModuleConfigData(Map configurationData, Module m, - VariableKey[] variableKeys) { - configurationData.put(m, mergeKeys(configurationData.get(m), variableKeys)); + configurationData.put(m, mergedKeyArray); } public static void initConfigurableVariables(Module rootModule, Map configurationData, From 9a8a93e67ee11486fd37a3f0c74389b5db4076b1 Mon Sep 17 00:00:00 2001 From: Ravin Perera <62183347+ravinperera00@users.noreply.github.com> Date: Mon, 20 May 2024 09:52:57 +0530 Subject: [PATCH 7/7] Remove unnecessary blank lines Co-authored-by: Hinduja Balasubramaniyam <28644893+HindujaB@users.noreply.github.com> --- .../java/io/ballerina/runtime/internal/launch/LaunchUtils.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java index 5bf84063d1fc..8ecd1a6d728c 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/launch/LaunchUtils.java @@ -95,10 +95,8 @@ public static void stopListeners(boolean isService) { public static void addModuleConfigData(Map configurationData, Module m, VariableKey[] variableKeys) { - VariableKey[] currKeys = configurationData.get(m); VariableKey[] mergedKeyArray; - if (currKeys == null) { mergedKeyArray = variableKeys; } else { @@ -106,7 +104,6 @@ public static void addModuleConfigData(Map configurationD System.arraycopy(currKeys, 0, mergedKeyArray, 0, currKeys.length); System.arraycopy(variableKeys, 0, mergedKeyArray, currKeys.length, variableKeys.length); } - configurationData.put(m, mergedKeyArray); }