diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 79680dd37886..426203e9c9e0 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -3,18 +3,31 @@
# See: https://help.github.com/articles/about-codeowners/
+* @gimantha
+
# Components
-/compiler/ @sameerajayasoma @hasithaa
-/langlib/ @sameerajayasoma @hasithaa
-/semtypes/ @sameerajayasoma @hasithaa
-/language-server/ @mohanvive @IMS94
-/ballerina-shell/ @mohanvive
+/compiler/ @sameerajayasoma @hasithaa @gimantha @MaryamZi
+/ballerina-shell/ @KavinduZoysa
+/build-config/ @keizer619
/bvm/ @warunalakshitha
-/observelib/ @nadundesilva
-/cli/ @hevayo
-/distribution/ @hevayo
-/misc/ @hevayo
-/project-api/ @hevayo @sameerajayasoma
+/cli/ @azinneera
+/distribution/ @keizer619
+/gradle/ @keizer619
+/langlib/ @sameerajayasoma @hasithaa @gimantha @MaryamZi
+/semtypes/ @gimantha @MaryamZi
+/language-server/ @KavinduZoysa
+/misc/ballerina-bindgen/ @warunalakshitha
+/misc/compiler-plugins/ @azinneera
+/misc/debug-adapter/ @NipunaRanasinghe
+/misc/docerina/ @keizer619
+/misc/identifier-util/ @warunalakshitha
+/misc/json-to-record-converter/ @NipunaRanasinghe
+/misc/semver-checker/ @NipunaRanasinghe
+/misc/testerina/ @azinneera @Dilhasha
+/misc/xml-to-record-converter/ @NipunaRanasinghe
+/project-api/ @azinneera @sameerajayasoma
+/performance/ @anuruddhal
+/tests/ @gimantha @MaryamZi @KavinduZoysa @warunalakshitha @azinneera
# CODEOWNERS file
-/.github/CODEOWNERS @sameerajayasoma @hasithaa @anupama-pathirage @warunalakshitha @mohanvive @manuranga @hevayo
+/.github/CODEOWNERS @sameerajayasoma @gimantha @MaryamZi @hasithaa
diff --git a/.github/workflows/pull_request_full_build.yml b/.github/workflows/pull_request_full_build.yml
index 2679e53676c4..1e24c1eb6cb9 100644
--- a/.github/workflows/pull_request_full_build.yml
+++ b/.github/workflows/pull_request_full_build.yml
@@ -43,6 +43,7 @@ jobs:
with:
name: Ballerina Lang Artifacts
path: ~/.m2/
+ include-hidden-files: true
outputs:
lang_version: ${{ steps.lang-version.outputs.version }}
diff --git a/.github/workflows/stale_check.yml b/.github/workflows/stale_check.yml
deleted file mode 100644
index 209dde589d47..000000000000
--- a/.github/workflows/stale_check.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-name: 'Close stale pull requests'
-
-on:
- schedule:
- - cron: '30 19 * * *'
- workflow_dispatch:
-
-jobs:
- stale:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/stale@v9
- with:
- stale-pr-message: 'This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the `stale` label is removed or commented.'
- close-pr-message: 'Closed PR due to inactivity for more than 18 days.'
- days-before-pr-stale: 15
- days-before-pr-close: 3
- days-before-issue-stale: -1
- days-before-issue-close: -1
diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/ReplShellApplication.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/ReplShellApplication.java
index c64ca77f276b..eb0880b6455b 100644
--- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/ReplShellApplication.java
+++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/ReplShellApplication.java
@@ -38,7 +38,11 @@
*
* @since 2.0.0
*/
-public class ReplShellApplication {
+public final class ReplShellApplication {
+
+ private ReplShellApplication() {
+ }
+
/**
* Executes the repl shell.
*
diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/JlineTerminalAdapter.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/JlineTerminalAdapter.java
index c37e27a58b17..9647488fb57f 100644
--- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/JlineTerminalAdapter.java
+++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/JlineTerminalAdapter.java
@@ -26,6 +26,8 @@
import org.jline.utils.AttributedStringBuilder;
import org.jline.utils.AttributedStyle;
+import java.io.PrintWriter;
+
/**
* Terminal adapter which encapsulates Jline.
*
@@ -56,10 +58,12 @@ public String readLine(String prefix, String postfix) throws ShellExitException
}
}
+ @SuppressWarnings("resource")
@Override
public void println(String text) {
- lineReader.getTerminal().writer().println(text);
- lineReader.getTerminal().writer().flush();
+ PrintWriter writer = lineReader.getTerminal().writer();
+ writer.println(text);
+ writer.flush();
}
@Override
diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/parser/ParserStateMachine.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/parser/ParserStateMachine.java
index 6bbfeb773894..d17cdc75b0a5 100644
--- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/parser/ParserStateMachine.java
+++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/jline/parser/ParserStateMachine.java
@@ -18,9 +18,10 @@
package io.ballerina.shell.cli.jline.parser;
+import java.util.ArrayDeque;
+import java.util.Deque;
import java.util.Map;
import java.util.Set;
-import java.util.Stack;
/**
* State machine implementation for ballerina parser.
@@ -65,12 +66,12 @@ public class ParserStateMachine {
CLOSE_PAREN, OPEN_PAREN,
CLOSE_SQ_BR, OPEN_SQ_BR);
- private final Stack stack;
+ private final Deque stack;
private ParserState state;
public ParserStateMachine() {
this.state = ParserState.NORMAL;
- this.stack = new Stack<>();
+ this.stack = new ArrayDeque<>();
}
public void feed(char character) {
@@ -138,9 +139,9 @@ private void normalStateOrAfterOperator(char character) {
case CLOSE_CURLY:
case CLOSE_PAREN:
case CLOSE_SQ_BR:
- if (!stack.empty() && OPEN_BRACKETS.get(character).equals(stack.peek())) {
+ if (!stack.isEmpty() && OPEN_BRACKETS.get(character).equals(stack.peek())) {
stack.pop();
- if (!stack.empty() && stack.peek() == BACKTICK) {
+ if (!stack.isEmpty() && stack.peek() == BACKTICK) {
state = ParserState.IN_TEMPLATE;
}
break;
@@ -238,7 +239,7 @@ private void inTemplateState(char character) {
state = ParserState.IN_TEMPLATE_AFTER_DOLLAR;
break;
case BACKTICK:
- if (!stack.empty() && stack.peek() == BACKTICK) {
+ if (!stack.isEmpty() && stack.peek() == BACKTICK) {
state = ParserState.NORMAL;
stack.pop();
break;
@@ -310,6 +311,6 @@ public boolean isIncomplete() {
return true;
}
// Otherwise, all brackets/backticks are closed is completion
- return !stack.empty();
+ return !stack.isEmpty();
}
}
diff --git a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/utils/FileUtils.java b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/utils/FileUtils.java
index 79cad030a59d..e853db527f0a 100644
--- a/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/utils/FileUtils.java
+++ b/ballerina-shell/modules/shell-cli/src/main/java/io/ballerina/shell/cli/utils/FileUtils.java
@@ -34,9 +34,13 @@
*
* @since 2.0.0
*/
-public class FileUtils {
+public final class FileUtils {
+
private static final String SPECIAL_DELIMITER = "\\A";
+ private FileUtils() {
+ }
+
/**
* Reads the file content from the resources.
*
diff --git a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/ShellSnippetsInvoker.java b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/ShellSnippetsInvoker.java
index 6b7ea3d4e1d2..19543b828c74 100644
--- a/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/ShellSnippetsInvoker.java
+++ b/ballerina-shell/modules/shell-core/src/main/java/io/ballerina/shell/invoker/ShellSnippetsInvoker.java
@@ -43,6 +43,7 @@
import io.ballerina.shell.invoker.classload.context.ClassLoadContext;
import io.ballerina.shell.snippet.Snippet;
import io.ballerina.shell.utils.StringUtils;
+import io.ballerina.tools.diagnostics.Diagnostic;
import io.ballerina.tools.diagnostics.DiagnosticSeverity;
import java.io.File;
@@ -277,7 +278,7 @@ protected PackageCompilation compile(Project project) throws InvokerException {
PackageCompilation packageCompilation = project.currentPackage().getCompilation();
DiagnosticResult diagnosticResult = packageCompilation.diagnosticResult();
- for (io.ballerina.tools.diagnostics.Diagnostic diagnostic : diagnosticResult.diagnostics()) {
+ for (Diagnostic diagnostic : diagnosticResult.diagnostics()) {
DiagnosticSeverity severity = diagnostic.diagnosticInfo().severity();
if (severity == DiagnosticSeverity.ERROR) {
containErrors = true;
@@ -329,7 +330,7 @@ protected void compileImportStatement(String importStatement) throws InvokerExce
* @return Whether the compilation contains MODULE_NOT_FOUND error.
*/
private boolean containsModuleNotFoundError(PackageCompilation compilation) {
- for (io.ballerina.tools.diagnostics.Diagnostic diagnostic : compilation.diagnosticResult().diagnostics()) {
+ for (Diagnostic diagnostic : compilation.diagnosticResult().diagnostics()) {
if (diagnostic.diagnosticInfo().code().equals(MODULE_NOT_FOUND_CODE)) {
return true;
}
@@ -435,9 +436,9 @@ protected Object invokeScheduledMethod(ClassLoader classLoader, String className
// Unexpected runtime error
throw new InvokerPanicException(panic);
}
- if (result instanceof Throwable) {
+ if (result instanceof Throwable throwable) {
// Function returned error (panic)
- throw new InvokerPanicException((Throwable) result);
+ throw new InvokerPanicException(throwable);
}
return result;
} catch (ClassNotFoundException e) {
@@ -512,7 +513,7 @@ private Function
*
* @since 0.995.0
+ * @param Type of the value returned by the iterator
*/
-public interface IteratorValue extends RefValue, BIterator {
+public interface IteratorValue extends RefValue, BIterator {
BTypedesc TYPEDESC = new TypedescValueImpl(PredefinedTypes.TYPE_ITERATOR);
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java
index 699747cf318d..53b0e46f92f2 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MapValueImpl.java
@@ -130,8 +130,8 @@ public MapValueImpl() {
@Override
public Long getIntValue(BString key) {
Object value = get(key);
- if (value instanceof Integer) { // field is an int subtype
- return ((Integer) value).longValue();
+ if (value instanceof Integer i) { // field is an int subtype
+ return i.longValue();
}
return (Long) value;
}
@@ -221,7 +221,7 @@ public V fillAndGet(Object key) {
// The type should be a record or map for filling read.
if (this.referredType.getTag() == TypeTags.RECORD_TYPE_TAG) {
BRecordType recordType = (BRecordType) this.referredType;
- Map fields = recordType.getFields();
+ Map, ?> fields = recordType.getFields();
if (fields.containsKey(key.toString())) {
expectedType = ((BField) fields.get(key.toString())).getFieldType();
} else {
@@ -248,7 +248,7 @@ public V fillAndGet(Object key) {
}
@Override
- public Object merge(BMap v2, boolean checkMergeability) {
+ public Object merge(BMap, ?> v2, boolean checkMergeability) {
if (checkMergeability) {
BError errorIfUnmergeable = JsonInternalUtils.getErrorIfUnmergeable(this, v2, new ArrayList<>());
if (errorIfUnmergeable != null) {
@@ -293,18 +293,13 @@ public V put(K key, V value) {
return putValue(key, value);
}
- String errMessage = "";
- switch (getImpliedType(getType()).getTag()) {
- case TypeTags.RECORD_TYPE_TAG:
- errMessage = "Invalid update of record field: ";
- break;
- case TypeTags.MAP_TAG:
- errMessage = "Invalid map insertion: ";
- break;
- }
+ String errMessage = switch (getImpliedType(getType()).getTag()) {
+ case TypeTags.RECORD_TYPE_TAG -> "Invalid update of record field: ";
+ case TypeTags.MAP_TAG -> "Invalid map insertion: ";
+ default -> "";
+ };
throw ErrorCreator.createError(getModulePrefixedReason(MAP_LANG_LIB, INVALID_UPDATE_ERROR_IDENTIFIER),
- StringUtils
- .fromString(errMessage).concat(ErrorHelper.getErrorMessage(
+ StringUtils.fromString(errMessage).concat(ErrorHelper.getErrorMessage(
INVALID_READONLY_VALUE_UPDATE)));
}
@@ -590,8 +585,8 @@ public void freezeDirect() {
this.referredType = ReadOnlyUtils.setImmutableTypeAndGetEffectiveType(this.referredType);
this.values().forEach(val -> {
- if (val instanceof BRefValue) {
- ((BRefValue) val).freezeDirect();
+ if (val instanceof BRefValue bRefValue) {
+ bRefValue.freezeDirect();
}
});
this.typedesc = null;
@@ -610,7 +605,7 @@ public String getJSONString() {
}
@Override
- public IteratorValue getIterator() {
+ public IteratorValue getIterator() {
return new MapIterator<>(new LinkedHashSet<>(this.entrySet()).iterator());
}
@@ -622,7 +617,7 @@ public IteratorValue getIterator() {
*
* @since 0.995.0
*/
- static class MapIterator implements IteratorValue {
+ static class MapIterator implements IteratorValue {
Iterator> iterator;
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MappingInitialValueEntry.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MappingInitialValueEntry.java
index de940b334394..3c51b8df6ed6 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MappingInitialValueEntry.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/MappingInitialValueEntry.java
@@ -56,9 +56,9 @@ public KeyValueEntry(Object key, Object value) {
*/
public static class SpreadFieldEntry extends MappingInitialValueEntry {
- public BMap values;
+ public BMap, ?> values;
- public SpreadFieldEntry(BMap mappingValue) {
+ public SpreadFieldEntry(BMap, ?> mappingValue) {
this.values = mappingValue;
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/NonBmpStringValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/NonBmpStringValue.java
index 38e4dc50cb6e..2210dfa05257 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/NonBmpStringValue.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/NonBmpStringValue.java
@@ -1,131 +1,131 @@
- /*
- * Copyright (c) 2019, 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.
- */
- package io.ballerina.runtime.internal.values;
+/*
+ * Copyright (c) 2019, 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.
+ */
+package io.ballerina.runtime.internal.values;
- import io.ballerina.runtime.api.utils.StringUtils;
+import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BString;
import java.util.Arrays;
- /**
- * Represent ballerina strings containing at least one non basic multilingual plane unicode character.
- *
- * @since 1.0.5
- */
- public class NonBmpStringValue extends StringValue {
+/**
+ * Represent ballerina strings containing at least one non basic multilingual plane unicode character.
+ *
+ * @since 1.0.5
+ */
+public class NonBmpStringValue extends StringValue {
- private final int[] surrogates;
+ private final int[] surrogates;
- public NonBmpStringValue(String value, int[] surrogatePairLocations) {
- super(value, true);
- surrogates = surrogatePairLocations;
- }
+ public NonBmpStringValue(String value, int[] surrogatePairLocations) {
+ super(value, true);
+ surrogates = surrogatePairLocations;
+ }
+
+ @Override
+ public int getCodePoint(int index) {
+ if ((index < 0) || (index >= value.length() - surrogates.length)) {
+ throw new StringIndexOutOfBoundsException(index);
+ }
+
+ int offset = index;
+ for (int surrogate : surrogates) {
+ if (surrogate < index) {
+ offset++;
+ } else if (surrogate > index) {
+ break;
+ } else {
+ return Character.toCodePoint(value.charAt(offset), value.charAt(offset + 1));
+ }
+ }
+ return value.charAt(offset);
+ }
+
+ @Override
+ public int length() {
+ return value.length() - surrogates.length;
+ }
+
+ @Override
+ public BString concat(BString str) {
+ StringValue stringValue = (StringValue) str;
+ if (stringValue.isNonBmp) {
+ NonBmpStringValue other = (NonBmpStringValue) str;
+ int[] both = Arrays.copyOf(surrogates, surrogates.length + other.surrogates.length);
+ int length = length();
+ for (int i = 0; i < other.surrogates.length; i++) {
+ both[i + surrogates.length] = other.surrogates[i] + length;
+ }
+ return new NonBmpStringValue(this.value + other.value, both);
+ }
+ return new NonBmpStringValue(this.value + str.getValue(), surrogates);
+ }
+
+ public int[] getSurrogates() {
+ return surrogates.clone();
+ }
@Override
- public int getCodePoint(int index) {
- if ((index < 0) || (index >= value.length() - surrogates.length)) {
- throw new StringIndexOutOfBoundsException(index);
+ public Long indexOf(BString str, int fromIndex) {
+ int offset = getOffset(fromIndex);
+ long index = value.indexOf(str.getValue(), offset);
+ if (index < 0) {
+ return null;
}
-
- int offset = index;
- for (int surrogate : surrogates) {
- if (surrogate < index) {
- offset++;
- } else if (surrogate > index) {
- break;
- } else {
- return Character.toCodePoint(value.charAt(offset), value.charAt(offset + 1));
+ for (int i = 0; i < index; i++) {
+ char c = value.charAt(i);
+ if (Character.isHighSurrogate(c)) {
+ index--;
}
}
- return value.charAt(offset);
+ return index;
}
@Override
- public int length() {
- return value.length() - surrogates.length;
+ public Long lastIndexOf(BString str, int fromIndex) {
+ int offset = getOffset(fromIndex);
+ long index = value.lastIndexOf(str.getValue(), offset);
+ if (index < 0) {
+ return null;
+ }
+ for (int i = 0; i < index; i++) {
+ char c = value.charAt(i);
+ if (Character.isHighSurrogate(c)) {
+ index--;
+ }
+ }
+ return index;
+ }
+ @Override
+ public BString substring(int beginIndex, int endIndex) {
+ int beginOffset = getOffset(beginIndex);
+ int endOffset = getOffset(endIndex);
+ return StringUtils.fromString(value.substring(beginOffset, endOffset));
}
- @Override
- public BString concat(BString str) {
- StringValue stringValue = (StringValue) str;
- if (stringValue.isNonBmp) {
- NonBmpStringValue other = (NonBmpStringValue) str;
- int[] both = Arrays.copyOf(surrogates, surrogates.length + other.surrogates.length);
- int length = length();
- for (int i = 0; i < other.surrogates.length; i++) {
- both[i + surrogates.length] = other.surrogates[i] + length;
+ private int getOffset(int fromIndex) {
+ int offset = fromIndex;
+ for (int surrogate : surrogates) {
+ if (surrogate < fromIndex) {
+ offset++;
+ } else {
+ break;
}
- return new NonBmpStringValue(this.value + other.value, both);
}
- return new NonBmpStringValue(this.value + str.getValue(), surrogates);
+ return offset;
}
-
- public int[] getSurrogates() {
- return surrogates.clone();
- }
-
- @Override
- public Long indexOf(BString str, int fromIndex) {
- int offset = getOffset(fromIndex);
- long index = value.indexOf(str.getValue(), offset);
- if (index < 0) {
- return null;
- }
- for (int i = 0; i < index; i++) {
- char c = value.charAt(i);
- if (Character.isHighSurrogate(c)) {
- index--;
- }
- }
- return index;
- }
-
- @Override
- public Long lastIndexOf(BString str, int fromIndex) {
- int offset = getOffset(fromIndex);
- long index = value.lastIndexOf(str.getValue(), offset);
- if (index < 0) {
- return null;
- }
- for (int i = 0; i < index; i++) {
- char c = value.charAt(i);
- if (Character.isHighSurrogate(c)) {
- index--;
- }
- }
- return index;
- }
- @Override
- public BString substring(int beginIndex, int endIndex) {
- int beginOffset = getOffset(beginIndex);
- int endOffset = getOffset(endIndex);
- return StringUtils.fromString(value.substring(beginOffset, endOffset));
- }
-
- private int getOffset(int fromIndex) {
- int offset = fromIndex;
- for (int surrogate : surrogates) {
- if (surrogate < fromIndex) {
- offset++;
- } else {
- break;
- }
- }
- return offset;
- }
- }
+}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ReadOnlyUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ReadOnlyUtils.java
index 5e527b31679f..819cca998c51 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ReadOnlyUtils.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/ReadOnlyUtils.java
@@ -66,7 +66,7 @@
*
* @since 1.3.0
*/
-public class ReadOnlyUtils {
+public final class ReadOnlyUtils {
/**
* Method to handle an update to a value, that is invalid due to the value being immutable.
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpAtomQuantifier.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpAtomQuantifier.java
index 2ca954b78553..21a3bef34c66 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpAtomQuantifier.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpAtomQuantifier.java
@@ -61,8 +61,8 @@ public void setReQuantifier(RegExpQuantifier reQuantifier) {
private Object getValidReAtom(Object reAtom) {
// If reAtom is an instance of BString it's an insertion. Hence, we need to parse it and check whether it's a
// valid insertion.
- if (reAtom instanceof BString) {
- validateInsertion((BString) reAtom);
+ if (reAtom instanceof BString bString) {
+ validateInsertion(bString);
}
return reAtom;
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpCharSet.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpCharSet.java
index 79d1e2612697..ff1b4d75f9a7 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpCharSet.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpCharSet.java
@@ -49,8 +49,8 @@ private Object[] getCharSetAtomsList(ArrayValue charSetAtoms) {
Object[] atoms = new Object[size];
for (int i = 0; i < size; i++) {
Object atom = charSetAtoms.get(i);
- if (atom instanceof BString) {
- atoms[i] = ((BString) atom).getValue();
+ if (atom instanceof BString bString) {
+ atoms[i] = bString.getValue();
continue;
}
atoms[i] = atom;
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpDisjunction.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpDisjunction.java
index 96f0cbfb0cf5..54cde1be1df8 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpDisjunction.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/RegExpDisjunction.java
@@ -55,8 +55,8 @@ public String stringValue(BLink parent) {
if (t == null) {
break;
}
- if (t instanceof String) {
- terms.add(((String) t));
+ if (t instanceof String s) {
+ terms.add(s);
continue;
}
terms.add(getStringVal(t, parent));
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StreamingJsonValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StreamingJsonValue.java
index af14dd66f4a9..e532436f0c9e 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StreamingJsonValue.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StreamingJsonValue.java
@@ -200,7 +200,7 @@ private void buildDatasource() {
}
@Override
- public IteratorValue getIterator() {
+ public IteratorValue getIterator() {
return new ArrayIterator(this);
}
@@ -209,7 +209,7 @@ public IteratorValue getIterator() {
*
* @since 0.995.0
*/
- static class StreamingJsonIterator implements IteratorValue {
+ static class StreamingJsonIterator implements IteratorValue {
StreamingJsonValue array;
long cursor = 0;
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StringValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StringValue.java
index a00c1c0e0575..a96fcacd5a07 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StringValue.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/StringValue.java
@@ -55,7 +55,7 @@ public Object frozenCopy(Map refs) {
}
@Override
- public IteratorValue getIterator() {
+ public IteratorValue getIterator() {
return new CharIterator(this);
}
@@ -94,8 +94,8 @@ public boolean equals(Object str) {
if (str == this) {
return true;
}
- if (str instanceof BString) {
- return ((BString) str).getValue().equals(value);
+ if (str instanceof BString bString) {
+ return bString.getValue().equals(value);
}
return false;
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TableValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TableValueImpl.java
index 510608521d8a..540f6371e222 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TableValueImpl.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TableValueImpl.java
@@ -149,7 +149,7 @@ public TableValueImpl(TableType tableType, ArrayValue fieldNames) {
}
private void addData(ArrayValue data) {
- BIterator itr = data.getIterator();
+ BIterator> itr = data.getIterator();
while (itr.hasNext()) {
Object next = itr.next();
valueHolder.addData((V) next);
@@ -157,7 +157,7 @@ private void addData(ArrayValue data) {
}
@Override
- public IteratorValue getIterator() {
+ public IteratorValue> getIterator() {
return new TableIterator();
}
@@ -178,7 +178,7 @@ public Object copy(Map refs) {
clone.fieldNames = fieldNames;
}
- IteratorValue itr = getIterator();
+ IteratorValue> itr = getIterator();
while (itr.hasNext()) {
TupleValueImpl tupleValue = (TupleValueImpl) itr.next();
Object value = tupleValue.get(1);
@@ -255,7 +255,7 @@ public Set> entrySet() {
for (List> entry: entries.values()) {
entrySet.addAll(entry);
}
- return new LinkedHashSet(entries.values());
+ return entrySet;
}
@Override
@@ -410,8 +410,8 @@ private String createExpressionStringValueDataEntry(Iterator> struct = itr.next();
@@ -510,7 +510,7 @@ public boolean equals(Object o, Set visitedValues) {
return true;
}
- private class TableIterator implements IteratorValue {
+ private class TableIterator implements IteratorValue {
private long cursor;
TableIterator() {
@@ -562,12 +562,12 @@ public V putData(K key, V data) {
}
public V putData(V data) {
- checkInherentTypeViolation((MapValue) data, tableType);
+ checkInherentTypeViolation((MapValue, ?>) data, tableType);
ArrayList newData = new ArrayList<>();
newData.add(data);
- Map.Entry entry = new AbstractMap.SimpleEntry(data, data);
+ Map.Entry entry = new AbstractMap.SimpleEntry<>((K) data, data);
List> entryList = new ArrayList<>();
entryList.add(entry);
UUID uuid = UUID.randomUUID();
@@ -608,7 +608,7 @@ public KeyHashValueHolder() {
@Override
public void addData(V data) {
- MapValue dataMap = (MapValue) data;
+ MapValue, ?> dataMap = (MapValue, ?>) data;
checkInherentTypeViolation(dataMap, tableType);
K key = this.keyWrapper.wrapKey(dataMap);
@@ -621,7 +621,7 @@ public void addData(V data) {
maxIntKey = ((Long) TypeChecker.anyToInt(key)).intValue();
}
- Map.Entry entry = new AbstractMap.SimpleEntry(key, data);
+ Map.Entry entry = new AbstractMap.SimpleEntry<>(key, data);
Long hash = TableUtils.hash(key, null);
if (entries.containsKey(hash)) {
@@ -652,8 +652,8 @@ public V getData(K key) {
@Override
public V putData(K key, V data) {
- Map.Entry entry = new AbstractMap.SimpleEntry(key, data);
- Object actualKey = this.keyWrapper.wrapKey((MapValue) data);
+ Map.Entry entry = new AbstractMap.SimpleEntry<>(key, data);
+ Object actualKey = this.keyWrapper.wrapKey((MapValue, ?>) data);
Long actualHash = TableUtils.hash(actualKey, null);
Long hash = TableUtils.hash(key, null);
@@ -681,7 +681,7 @@ private V putNewData(K key, V value, Map.Entry entry, Long hash) {
@Override
public V putData(V data) {
- MapValue dataMap = (MapValue) data;
+ MapValue, ?> dataMap = (MapValue, ?>) data;
checkInherentTypeViolation(dataMap, tableType);
K key = this.keyWrapper.wrapKey(dataMap);
Map.Entry entry = new AbstractMap.SimpleEntry<>(key, data);
@@ -774,7 +774,7 @@ public DefaultKeyWrapper() {
}
}
- public K wrapKey(MapValue data) {
+ public K wrapKey(MapValue, ?> data) {
return (K) data.get(StringUtils.fromString(fieldNames[0]));
}
}
@@ -797,7 +797,7 @@ public MultiKeyWrapper() {
}
@Override
- public K wrapKey(MapValue data) {
+ public K wrapKey(MapValue, ?> data) {
TupleValueImpl arr = (TupleValueImpl) ValueCreator
.createTupleValue((BTupleType) keyType);
for (int i = 0; i < fieldNames.length; i++) {
@@ -830,7 +830,7 @@ private void updateIndexKeyMappings(Long hash, K key, V value) {
}
// This method checks for inherent table type violation
- private void checkInherentTypeViolation(MapValue dataMap, TableType type) {
+ private void checkInherentTypeViolation(MapValue, ?> dataMap, TableType type) {
if (!TypeChecker.checkIsType(dataMap.getType(), type.getConstrainedType())) {
BString reason = getModulePrefixedReason(TABLE_LANG_LIB, INHERENT_TYPE_VIOLATION_ERROR_IDENTIFIER);
BString detail = StringUtils.fromString("value type '" + dataMap.getType() + "' inconsistent with the " +
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java
index baf8b1029ff4..922b1ce59a21 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TupleValueImpl.java
@@ -266,8 +266,8 @@ public boolean getBoolean(long index) {
@Override
public byte getByte(long index) {
Object value = get(index);
- if (value instanceof Long) {
- return ((Long) value).byteValue();
+ if (value instanceof Long l) {
+ return l.byteValue();
}
return (Byte) value;
}
@@ -426,10 +426,12 @@ public Object shift(long index) {
return shift(index, "shift");
}
+ @Override
public Object pop(long index) {
return shift(index, "pop");
}
+ @Override
public Object remove(long index) {
return shift(index, "remove");
}
@@ -530,8 +532,8 @@ public Object copy(Map refs) {
refs.put(this, refValueArray);
IntStream.range(0, this.size).forEach(i -> {
Object value = this.refValues[i];
- if (value instanceof BRefValue) {
- values[i] = ((BRefValue) value).copy(refs);
+ if (value instanceof BRefValue bRefValue) {
+ values[i] = bRefValue.copy(refs);
} else {
values[i] = value;
}
@@ -617,8 +619,8 @@ public void freezeDirect() {
this.tupleType = (TupleType) TypeUtils.getImpliedType(type);
for (int i = 0; i < this.size; i++) {
Object value = this.get(i);
- if (value instanceof BRefValue) {
- ((BRefValue) value).freezeDirect();
+ if (value instanceof BRefValue bRefValue) {
+ bRefValue.freezeDirect();
}
}
this.typedesc = null;
@@ -628,7 +630,7 @@ public void freezeDirect() {
* {@inheritDoc}
*/
@Override
- public IteratorValue getIterator() {
+ public IteratorValue getIterator() {
return new ArrayIterator(this);
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java
index bea73113906a..39dc6347600a 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/TypedescValueImpl.java
@@ -25,6 +25,7 @@
import io.ballerina.runtime.api.values.BLink;
import io.ballerina.runtime.api.values.BListInitialValueEntry;
import io.ballerina.runtime.api.values.BMapInitialValueEntry;
+import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.api.values.BTypedesc;
import io.ballerina.runtime.internal.scheduling.Strand;
import io.ballerina.runtime.internal.types.BAnnotatableType;
@@ -53,8 +54,8 @@ public class TypedescValueImpl implements TypedescValue {
final Type type;
final Type describingType; // Type of the value describe by this typedesc.
- public MapValue[] closures;
- public MapValue annotations;
+ public MapValue, ?>[] closures;
+ public MapValue, ?> annotations;
private BTypedesc typedesc;
public TypedescValueImpl(Type describingType) {
@@ -62,13 +63,13 @@ public TypedescValueImpl(Type describingType) {
this.describingType = describingType;
}
- public TypedescValueImpl(Type describingType, MapValue[] closures) {
+ public TypedescValueImpl(Type describingType, MapValue, ?>[] closures) {
this.type = new BTypedescType(describingType);
this.describingType = describingType;
this.closures = closures;
}
- public TypedescValueImpl(Type describingType, MapValue[] closures, MapValue annotations) {
+ public TypedescValueImpl(Type describingType, MapValue, ?>[] closures, MapValue annotations) {
this(describingType, closures);
this.annotations = annotations;
((BAnnotatableType) describingType).setAnnotations(annotations);
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlComment.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlComment.java
index 24725ac7bca8..00cab7fe4d6b 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlComment.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlComment.java
@@ -47,9 +47,9 @@ public XmlComment(String data, boolean readonly) {
}
@Override
- public IteratorValue getIterator() {
+ public IteratorValue getIterator() {
XmlComment that = this;
- return new IteratorValue() {
+ return new IteratorValue<>() {
boolean read = false;
@Override
public boolean hasNext() {
@@ -57,7 +57,7 @@ public boolean hasNext() {
}
@Override
- public Object next() {
+ public XmlComment next() {
if (!read) {
this.read = true;
return that;
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java
index 345e40f8779f..596a091cbc78 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java
@@ -385,7 +385,7 @@ private BError createXMLCycleError() {
StringUtils.fromString("Cycle detected"));
}
- private void mergeAdjoiningTextNodesIntoList(List leftList, List appendingList) {
+ private void mergeAdjoiningTextNodesIntoList(List leftList, List appendingList) {
XmlText lastChild = (XmlText) leftList.get(leftList.size() - 1);
String firstChildContent = appendingList.get(0).getTextValue();
String mergedTextContent = lastChild.getTextValue() + firstChildContent;
@@ -509,8 +509,7 @@ public Object copy(Map refs) {
MapValue attributesMap = xmlItem.getAttributesMap();
MapValue copy = (MapValue) this.getAttributesMap().copy(refs);
- if (attributesMap instanceof MapValueImpl) {
- MapValueImpl map = (MapValueImpl) attributesMap;
+ if (attributesMap instanceof MapValueImpl map) {
map.putAll((Map) copy);
} else {
for (Map.Entry entry : copy.entrySet()) {
@@ -663,9 +662,9 @@ public BXmlSequence getChildrenSeq() {
}
@Override
- public IteratorValue getIterator() {
+ public IteratorValue getIterator() {
XmlItem that = this;
- return new IteratorValue() {
+ return new IteratorValue<>() {
boolean read = false;
@Override
@@ -674,7 +673,7 @@ public boolean hasNext() {
}
@Override
- public Object next() {
+ public XmlItem next() {
if (read) {
throw new NoSuchElementException();
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlNonElementItem.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlNonElementItem.java
index 0a40cc982b3c..8a404e5b755e 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlNonElementItem.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlNonElementItem.java
@@ -176,15 +176,15 @@ public void removeChildren(String qname) {
public abstract OMNode value();
@Override
- public IteratorValue getIterator() {
- return new IteratorValue() {
+ public IteratorValue> getIterator() {
+ return new IteratorValue<>() {
@Override
public boolean hasNext() {
return false;
}
@Override
- public Object next() {
+ public Void next() {
throw new NoSuchElementException();
}
};
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlPi.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlPi.java
index 764b4e88d460..61f8982271fb 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlPi.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlPi.java
@@ -51,9 +51,9 @@ public XmlPi(String data, String target, boolean readonly) {
}
@Override
- public IteratorValue getIterator() {
+ public IteratorValue getIterator() {
XmlPi that = this;
- return new IteratorValue() {
+ return new IteratorValue<>() {
boolean read = false;
@Override
public boolean hasNext() {
@@ -61,7 +61,7 @@ public boolean hasNext() {
}
@Override
- public Object next() {
+ public XmlPi next() {
if (!read) {
this.read = true;
return that;
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java
index 126983bd1884..03347dfa93c6 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlSequence.java
@@ -31,6 +31,7 @@
import io.ballerina.runtime.api.values.BXmlSequence;
import io.ballerina.runtime.internal.CycleUtils;
import io.ballerina.runtime.internal.IteratorUtils;
+import io.ballerina.runtime.internal.XmlFactory;
import io.ballerina.runtime.internal.errors.ErrorCodes;
import io.ballerina.runtime.internal.errors.ErrorHelper;
import io.ballerina.runtime.internal.types.BArrayType;
@@ -70,8 +71,12 @@ public XmlSequence() {
this.type = PredefinedTypes.TYPE_XML_NEVER;
}
- public XmlSequence(List children) {
- this.children = children;
+ public XmlSequence(List values) {
+ if (values.isEmpty()) {
+ this.children = values;
+ return;
+ }
+ setSequenceMembersConcatenatingAdjacentTextItems(values);
}
public XmlSequence(BXml child) {
@@ -214,7 +219,7 @@ public void setAttributes(BMap attributes) {
*/
@Override
public XmlValue elements() {
- List elementsSeq = new ArrayList();
+ List elementsSeq = new ArrayList<>();
for (BXml child : children) {
if (child.getNodeType() == XmlNodeType.ELEMENT) {
elementsSeq.add(child);
@@ -612,8 +617,8 @@ public boolean isFrozen() {
}
@Override
- public IteratorValue getIterator() {
- return new IteratorValue() {
+ public IteratorValue getIterator() {
+ return new IteratorValue<>() {
Iterator iterator = children.iterator();
@Override
@@ -622,12 +627,35 @@ public boolean hasNext() {
}
@Override
- public Object next() {
+ public BXml next() {
return iterator.next();
}
};
}
+ private void setSequenceMembersConcatenatingAdjacentTextItems(List values) {
+ ArrayList members = new ArrayList<>();
+ boolean isPreviousValueText = false;
+ StringBuilder text = new StringBuilder();
+ for (BXml value : values) {
+ if (value.getNodeType() == XmlNodeType.TEXT) {
+ isPreviousValueText = true;
+ text.append(value.getTextValue());
+ continue;
+ }
+ if (isPreviousValueText) {
+ members.add(XmlFactory.createXMLText(StringUtils.fromString(text.toString())));
+ isPreviousValueText = false;
+ text.setLength(0);
+ }
+ members.add(value);
+ }
+ if (!text.isEmpty()) {
+ members.add(XmlFactory.createXMLText(StringUtils.fromString(text.toString())));
+ }
+ this.children = members;
+ }
+
private Type getSequenceType(Type tempExprType) {
return switch (tempExprType.getTag()) {
case TypeTags.XML_ELEMENT_TAG -> PredefinedTypes.TYPE_XML_ELEMENT_SEQUENCE;
@@ -643,8 +671,8 @@ private void initializeIteratorNextReturnType() {
childrenType = children.get(0).getType();
} else {
Set types = new HashSet<>();
- for (int i = 0; i < children.size(); i++) {
- types.add(children.get(i).getType());
+ for (BXml child : children) {
+ types.add(child.getType());
}
childrenType = new BUnionType(new ArrayList<>(types));
}
@@ -671,9 +699,8 @@ public boolean equals(Object o, Set visitedValues) {
if (o instanceof XmlSequence rhsXMLSequence) {
return isXMLSequenceChildrenEqual(this.getChildrenList(), rhsXMLSequence.getChildrenList());
}
- if (o instanceof XmlItem) {
- return this.getChildrenList().size() == 1 &&
- isEqual(this.getChildrenList().get(0), o);
+ if (this.isSingleton() && (o instanceof XmlValue)) {
+ return isEqual(this.getChildrenList().get(0), o);
}
return this.getChildrenList().isEmpty() && TypeUtils.getType(o) == PredefinedTypes.TYPE_XML_NEVER;
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlText.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlText.java
index 396d9807abb0..d1ea4cd8306d 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlText.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlText.java
@@ -92,9 +92,9 @@ public OMNode value() {
}
@Override
- public IteratorValue getIterator() {
+ public IteratorValue getIterator() {
XmlText that = this;
- return new IteratorValue() {
+ return new IteratorValue<>() {
boolean read = false;
@Override
public boolean hasNext() {
@@ -102,7 +102,7 @@ public boolean hasNext() {
}
@Override
- public Object next() {
+ public XmlText next() {
if (!read) {
this.read = true;
return that;
@@ -127,11 +127,11 @@ public boolean equals(Object obj) {
*/
@Override
public boolean equals(Object o, Set visitedValues) {
- if (o instanceof XmlText rhsXMLText) {
- return this.getTextValue().equals(rhsXMLText.getTextValue());
+ if ((o instanceof XmlText) || isXmlSequenceWithSingletonTextValue(o)) {
+ return this.getTextValue().equals(((XmlValue) o).getTextValue());
}
- return this.getType() == PredefinedTypes.TYPE_XML_NEVER && (o instanceof XmlSequence) &&
- ((XmlSequence) o).getChildrenList().isEmpty();
+ return this.getType() == PredefinedTypes.TYPE_XML_NEVER && (o instanceof XmlSequence xmlSequence) &&
+ xmlSequence.getChildrenList().isEmpty();
}
@Override
@@ -143,4 +143,11 @@ public int hashCode() {
public Type getType() {
return this.type;
}
+
+ private boolean isXmlSequenceWithSingletonTextValue(Object o) {
+ if (!(o instanceof XmlSequence sequence)) {
+ return false;
+ }
+ return sequence.isSingleton() && sequence.getItem(0).getNodeType() == XmlNodeType.TEXT;
+ }
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlValue.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlValue.java
index f6a3b813f4ea..23443629ca47 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlValue.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlValue.java
@@ -244,8 +244,8 @@ public Object frozenCopy(Map refs) {
@Override
public void serialize(OutputStream outputStream) {
try {
- if (outputStream instanceof BallerinaXmlSerializer) {
- ((BallerinaXmlSerializer) outputStream).write(this);
+ if (outputStream instanceof BallerinaXmlSerializer xmlSerializer) {
+ xmlSerializer.write(this);
} else {
BallerinaXmlSerializer xmlSerializer = new BallerinaXmlSerializer(outputStream);
xmlSerializer.write(this);
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObservabilityConstants.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObservabilityConstants.java
index ccda1782adff..c519b3185f66 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObservabilityConstants.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObservabilityConstants.java
@@ -24,7 +24,7 @@
* Open Tracing Specification.
*
*/
-public class ObservabilityConstants {
+public final class ObservabilityConstants {
private ObservabilityConstants() {
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObserveUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObserveUtils.java
index dcc52ccd6b5a..759bf3f0210b 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObserveUtils.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/ObserveUtils.java
@@ -63,7 +63,8 @@
*
* @since 0.985.0
*/
-public class ObserveUtils {
+public final class ObserveUtils {
+
private static final List observers = new CopyOnWriteArrayList<>();
private static final boolean enabled;
private static final boolean metricsEnabled;
@@ -96,6 +97,9 @@ public class ObserveUtils {
enabled = metricsEnabled || tracingEnabled;
}
+ private ObserveUtils() {
+ }
+
private static T readConfig(VariableKey specificKey, VariableKey inheritedKey, T defaultValue) {
T value;
if (ConfigMap.containsKey(specificKey)) {
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/DefaultMetricRegistry.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/DefaultMetricRegistry.java
index 4004e6888571..f088a929ba8d 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/DefaultMetricRegistry.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/DefaultMetricRegistry.java
@@ -24,10 +24,13 @@
/**
* Hold a default {@link MetricRegistry} instance, which is used by Metric APIs.
*/
-public class DefaultMetricRegistry {
+public final class DefaultMetricRegistry {
private static MetricRegistry instance = new MetricRegistry(new NoOpMetricProvider());
+ private DefaultMetricRegistry() {
+ }
+
/**
* Get the default {@link MetricRegistry}.
*
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricConstants.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricConstants.java
index c2f16d24da44..e6e29a1272df 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricConstants.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/MetricConstants.java
@@ -21,7 +21,7 @@
* Defines the types of the metrics supported.
* @since 0.980.0
*/
-public class MetricConstants {
+public final class MetricConstants {
private MetricConstants() {}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/PolledGauge.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/PolledGauge.java
index 58bfcbd99e87..e59bca0886a8 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/PolledGauge.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/PolledGauge.java
@@ -67,25 +67,25 @@ public Builder description(String description) {
}
@Override
- public Builder tags(String... keyValues) {
+ public Builder tags(String... keyValues) {
Tags.tags(this.tags, keyValues);
return this;
}
@Override
- public Builder tags(Iterable tags) {
+ public Builder tags(Iterable tags) {
Tags.tags(this.tags, tags);
return this;
}
@Override
- public Builder tag(String key, String value) {
+ public Builder tag(String key, String value) {
Tags.tags(this.tags, key, value);
return this;
}
@Override
- public Builder tags(Map tags) {
+ public Builder tags(Map tags) {
Tags.tags(this.tags, tags);
return this;
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/Tags.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/Tags.java
index 03468bdc3255..8314ecbecd5a 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/Tags.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/metrics/Tags.java
@@ -23,7 +23,7 @@
/**
* Utility methods to add tags to an existing list of {@link Tag Tags}.
*/
-public class Tags {
+public final class Tags {
private Tags() {
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TraceConstants.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TraceConstants.java
index c3d811e3ff4f..1b74c86b47e8 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TraceConstants.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TraceConstants.java
@@ -25,7 +25,7 @@
*
* @since 0.964.1
*/
-public class TraceConstants {
+public final class TraceConstants {
private TraceConstants() {
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java
index 819c8e171902..1747c16ac9b4 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/observability/tracer/TracingUtils.java
@@ -34,7 +34,7 @@
/**
* Util class to hold tracing specific util methods.
*/
-public class TracingUtils {
+public final class TracingUtils {
private TracingUtils() {
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionConstants.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionConstants.java
index f7ee5d9e9d8a..e8cfd5af24ac 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionConstants.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionConstants.java
@@ -31,7 +31,8 @@
*
* @since 1.0
*/
-public class TransactionConstants {
+public final class TransactionConstants {
+
//Co-ordinator functions
public static final String COORDINATOR_ABORT_TRANSACTION = "abortTransaction";
@@ -72,4 +73,7 @@ public class TransactionConstants {
public static final String TIMESTAMP_OBJECT_VALUE_FIELD = "timeValue";
public static final int DEFAULT_TRX_AUTO_COMMIT_TIMEOUT = 120;
public static final int DEFAULT_TRX_CLEANUP_TIMEOUT = 600;
+
+ private TransactionConstants() {
+ }
}
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java
index 64973ab681ab..3dad3d68f0e9 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionLocalContext.java
@@ -22,9 +22,10 @@
import io.ballerina.runtime.internal.scheduling.Strand;
import java.nio.ByteBuffer;
+import java.util.ArrayDeque;
+import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
-import java.util.Stack;
/**
* {@code TransactionLocalContext} stores the transaction related information.
@@ -41,8 +42,8 @@ public class TransactionLocalContext {
private Map allowedTransactionRetryCounts;
private Map currentTransactionRetryCounts;
private Map transactionContextStore;
- private Stack transactionBlockIdStack;
- private Stack transactionFailure;
+ private Deque transactionBlockIdStack;
+ private Deque transactionFailure;
private static final TransactionResourceManager transactionResourceManager =
TransactionResourceManager.getInstance();
private boolean isResourceParticipant;
@@ -59,8 +60,8 @@ private TransactionLocalContext(String globalTransactionId, String url, String p
this.allowedTransactionRetryCounts = new HashMap<>();
this.currentTransactionRetryCounts = new HashMap<>();
this.transactionContextStore = new HashMap<>();
- this.transactionBlockIdStack = new Stack<>();
- this.transactionFailure = new Stack<>();
+ this.transactionBlockIdStack = new ArrayDeque<>();
+ this.transactionFailure = new ArrayDeque<>();
this.rollbackOnlyError = null;
this.isTransactional = true;
this.transactionId = ValueCreator.createArrayValue(globalTransactionId.getBytes());
@@ -104,7 +105,7 @@ public void addCurrentTransactionBlockId(String blockId) {
}
public boolean hasTransactionBlock() {
- return !transactionBlockIdStack.empty();
+ return !transactionBlockIdStack.isEmpty();
}
public String getURL() {
@@ -211,7 +212,7 @@ public void markFailure() {
}
public TransactionFailure getAndClearFailure() {
- if (transactionFailure.empty()) {
+ if (transactionFailure.isEmpty()) {
return null;
}
TransactionFailure failure = transactionFailure.pop();
@@ -220,7 +221,7 @@ public TransactionFailure getAndClearFailure() {
}
public TransactionFailure getFailure() {
- if (transactionFailure.empty()) {
+ if (transactionFailure.isEmpty()) {
return null;
}
return transactionFailure.peek();
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java
index da7c241b5116..743c1dc2fd58 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionResourceManager.java
@@ -95,8 +95,8 @@ public class TransactionResourceManager {
private Map trxRegistry;
private Map xidRegistry;
- private Map> committedFuncRegistry;
- private Map> abortedFuncRegistry;
+ private Map>> committedFuncRegistry;
+ private Map>> abortedFuncRegistry;
private ConcurrentSkipListSet failedResourceParticipantSet = new ConcurrentSkipListSet<>();
private ConcurrentSkipListSet failedLocalParticipantSet = new ConcurrentSkipListSet<>();
@@ -259,7 +259,7 @@ public void register(String transactionId, String transactionBlockId, BallerinaT
* @param transactionBlockId the block id of the transaction
* @param fpValue the function pointer for the committed function
*/
- public void registerCommittedFunction(String transactionBlockId, BFunctionPointer fpValue) {
+ public void registerCommittedFunction(String transactionBlockId, BFunctionPointer, ?> fpValue) {
if (fpValue != null) {
committedFuncRegistry.computeIfAbsent(transactionBlockId, list -> new ArrayList<>()).add(fpValue);
}
@@ -271,7 +271,7 @@ public void registerCommittedFunction(String transactionBlockId, BFunctionPointe
* @param transactionBlockId the block id of the transaction
* @param fpValue the function pointer for the aborted function
*/
- public void registerAbortedFunction(String transactionBlockId, BFunctionPointer fpValue) {
+ public void registerAbortedFunction(String transactionBlockId, BFunctionPointer, ?> fpValue) {
if (fpValue != null) {
abortedFuncRegistry.computeIfAbsent(transactionBlockId, list -> new ArrayList<>()).add(fpValue);
}
@@ -532,7 +532,7 @@ public void notifyTransactionAbort(String transactionBlockId) {
* @return Array of rollback handlers
*/
public BArray getRegisteredRollbackHandlerList() {
- List abortFunctions =
+ List> abortFunctions =
abortedFuncRegistry.get(Scheduler.getStrand().currentTrxContext.getGlobalTransactionId());
if (abortFunctions != null && !abortFunctions.isEmpty()) {
Collections.reverse(abortFunctions);
@@ -548,7 +548,7 @@ public BArray getRegisteredRollbackHandlerList() {
* @return Array of commit handlers
*/
public BArray getRegisteredCommitHandlerList() {
- List commitFunctions =
+ List> commitFunctions =
committedFuncRegistry.get(Scheduler.getStrand().currentTrxContext.getGlobalTransactionId());
if (commitFunctions != null && !commitFunctions.isEmpty()) {
Collections.reverse(commitFunctions);
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionUtils.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionUtils.java
index 37d17656df56..33b0f88edcdc 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionUtils.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/TransactionUtils.java
@@ -47,12 +47,15 @@
*
* @since 1.0
*/
-public class TransactionUtils {
+public final class TransactionUtils {
private static final StrandMetadata TRX_METADATA = new StrandMetadata(BALLERINA_BUILTIN_PKG_PREFIX,
TRANSACTION_PACKAGE_NAME,
TRANSACTION_PACKAGE_VERSION, "onAbort");
+ private TransactionUtils() {
+ }
+
public static void notifyTransactionAbort(Strand strand, String globalTransactionId, String transactionBlockId) {
executeFunction(strand.scheduler, TransactionUtils.class.getClassLoader(), TRANSACTION_PACKAGE_FQN,
TRANSACTION_BLOCK_CLASS_NAME, COORDINATOR_ABORT_TRANSACTION, globalTransactionId,
diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/XIDGenerator.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/XIDGenerator.java
index bd3b05674d87..4131ba35b8d5 100644
--- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/XIDGenerator.java
+++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/transactions/XIDGenerator.java
@@ -25,7 +25,7 @@
*
* @since 1.0
*/
-public class XIDGenerator {
+public final class XIDGenerator {
private static final SecureRandom secureRand = new SecureRandom();
private static final AtomicInteger formatIdIdGenerator = new AtomicInteger();
diff --git a/bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/RuntimeUtilTests.java b/bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/RuntimeUtilTests.java
index f004dfb8fcb9..2d862f8909be 100644
--- a/bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/RuntimeUtilTests.java
+++ b/bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/RuntimeUtilTests.java
@@ -49,8 +49,8 @@ public void testVerifyJavaCompatibilityNegative() {
// versions in the format" {compiledVersion, runtimeVersion, supportedVersionRange}
String[][] versions = { { "1.8.0_144", "1.7.0_1", "1.8.*" }, { "1.8.0_144", "9", "1.8.*" },
{ "9.0.1", "10.0.2.1", "9.0.*" }, { "9", "10.0.2.1", "9.0.*" }, { "10", "9", "10.0.*" } };
- for (int i = 0; i < versions.length; i++) {
- testVersionsNegative(versions[i][0], versions[i][1], versions[i][2]);
+ for (String[] version : versions) {
+ testVersionsNegative(version[0], version[1], version[2]);
}
}
@@ -59,8 +59,8 @@ public void testVerifyJavaCompatibilityPositive() {
// versions in the format" {compiledVersion, runtimeVersion}
String[][] versions = { { "1.8.0_144", "1.8.0_144" }, { "1.8.0_144", "1.8.0_221" }, { "9.0_221", "9" },
{ "9", "9.0_221" }, { "10.0.1", "10.0.2.1" }, { "10", "10" } };
- for (int i = 0; i < versions.length; i++) {
- testVersionsPositive(versions[i][0], versions[i][1]);
+ for (String[] version : versions) {
+ testVersionsPositive(version[0], version[1]);
}
}
diff --git a/bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/TestUtils.java b/bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/TestUtils.java
index 7d703830a2b9..b663f5b4ab6d 100644
--- a/bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/TestUtils.java
+++ b/bvm/ballerina-runtime/src/test/java/io/ballerina/runtime/test/TestUtils.java
@@ -31,7 +31,10 @@
* Utils class for runtime unit tests.
* @since 2.0.0
*/
-public class TestUtils {
+public final class TestUtils {
+
+ private TestUtils() {
+ }
public static Path getConfigPath(String configFileName) {
return Paths.get(RuntimeUtils.USER_DIR, "src", "test", "resources", "config_files", configFileName);
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java
index 27212ddfeb2a..8db23f80deec 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/CommandUtil.java
@@ -104,7 +104,8 @@
*
* @since 2.0.0
*/
-public class CommandUtil {
+public final class CommandUtil {
+
public static final String ORG_NAME = "ORG_NAME";
public static final String PKG_NAME = "PKG_NAME";
public static final String DIST_VERSION = "DIST_VERSION";
@@ -126,6 +127,9 @@ public class CommandUtil {
private static boolean exitWhenFinish;
private static String platform;
+ private CommandUtil() {
+ }
+
static void setPrintStream(PrintStream errStream) {
CommandUtil.errStream = errStream;
}
@@ -872,21 +876,22 @@ private static void createDefaultDevContainer(Path path) throws IOException {
public static List getTemplates() {
try {
Path templateDir = getTemplatePath();
- Stream walk = Files.walk(templateDir, 1);
+ try (Stream walk = Files.walk(templateDir, 1)) {
- List templates = walk.filter(Files::isDirectory)
+ List templates = walk.filter(Files::isDirectory)
.filter(directory -> !templateDir.equals(directory))
.map(directory -> directory.getFileName())
.filter(Objects::nonNull)
.map(Path::toString)
- .collect(Collectors.toList());
+ .toList();
- if (null != jarFs) {
- return templates.stream().map(t -> t
- .replace(jarFs.getSeparator(), ""))
- .collect(Collectors.toList());
- } else {
- return templates;
+ if (null != jarFs) {
+ return templates.stream().map(t -> t
+ .replace(jarFs.getSeparator(), ""))
+ .toList();
+ } else {
+ return templates;
+ }
}
} catch (IOException | URISyntaxException e) {
@@ -1000,7 +1005,7 @@ private static void initToolPackage(Path path, String packageName) throws IOExce
Files.writeString(balToolToml, balToolManifest);
}
- protected static PackageVersion findLatest(List packageVersions) {
+ private static PackageVersion findLatest(List packageVersions) {
if (packageVersions.isEmpty()) {
return null;
}
@@ -1011,7 +1016,7 @@ protected static PackageVersion findLatest(List packageVersions)
return latestVersion;
}
- protected static PackageVersion getLatest(PackageVersion v1, PackageVersion v2) {
+ private static PackageVersion getLatest(PackageVersion v1, PackageVersion v2) {
SemanticVersion semVer1 = v1.value();
SemanticVersion semVer2 = v2.value();
boolean isV1PreReleaseVersion = semVer1.isPreReleaseVersion();
@@ -1035,7 +1040,7 @@ public static List getPackageVersions(Path balaPackagePath) {
return pathToVersions(versions);
}
- protected static List pathToVersions(List versions) {
+ private static List pathToVersions(List versions) {
List availableVersions = new ArrayList<>();
versions.stream().map(path -> Optional.ofNullable(path)
.map(Path::getFileName)
@@ -1084,8 +1089,10 @@ private static String removeLastCharacter(String str) {
public static String checkTemplateFilesExists(String template, Path packagePath) throws URISyntaxException,
IOException {
Path templateDir = getTemplatePath().resolve(template);
- Stream paths = Files.list(templateDir);
- List templateFilePathList = paths.toList();
+ List templateFilePathList;
+ try (Stream paths = Files.list(templateDir)) {
+ templateFilePathList = paths.toList();
+ }
StringBuilder existingFiles = new StringBuilder();
for (Path path : templateFilePathList) {
Optional fileNameOptional = Optional.ofNullable(path.getFileName()).map(Path::toString);
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/Constants.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/Constants.java
index f07d647eaa9f..ea52c012f1d0 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/Constants.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/Constants.java
@@ -22,7 +22,8 @@
*
* @since 2.0.0
*/
-public class Constants {
+public final class Constants {
+
public static final String BUILD_COMMAND = "build";
public static final String RUN_COMMAND = "run";
public static final String DOC_COMMAND = "doc";
@@ -61,4 +62,7 @@ public class Constants {
public static final String DEBUG_OPTION = "--debug";
public static final String VERSION_SHORT_OPTION = "-v";
public static final String HELP_SHORT_OPTION = "-h";
+
+ private Constants() {
+ }
}
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PullCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PullCommand.java
index 1b201d6c8c3e..79fb92c02971 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PullCommand.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PullCommand.java
@@ -30,6 +30,7 @@
import io.ballerina.projects.internal.model.Repository;
import io.ballerina.projects.util.ProjectConstants;
import io.ballerina.projects.util.ProjectUtils;
+import org.apache.commons.io.FileUtils;
import org.ballerinalang.central.client.CentralAPIClient;
import org.ballerinalang.central.client.CentralClientConstants;
import org.ballerinalang.central.client.exceptions.CentralClientException;
@@ -311,8 +312,7 @@ private void pullFromMavenRepo(Settings settings, String orgName, String package
JsonObject resultObj = new Gson().fromJson(bufferedReader, JsonObject.class);
String platform = resultObj.get(PLATFORM).getAsString();
Path actualBalaPath = mavenBalaCachePath.resolve(platform);
- org.apache.commons.io.FileUtils.copyDirectory(temporaryExtractionPath.toFile(),
- actualBalaPath.toFile());
+ FileUtils.copyDirectory(temporaryExtractionPath.toFile(), actualBalaPath.toFile());
}
} catch (MavenResolverClientException e) {
errStream.println("unexpected error occurred while pulling package:" + e.getMessage());
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/BallerinaCliCommands.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/BallerinaCliCommands.java
index 8d36f6b0ad62..e65001c91377 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/BallerinaCliCommands.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/BallerinaCliCommands.java
@@ -22,11 +22,14 @@
*
* @since 0.970.0
*/
-public class BallerinaCliCommands {
+public final class BallerinaCliCommands {
public static final String DEFAULT = "default";
public static final String HELP = "help";
public static final String VERSION = "version";
public static final String RUN = "run";
public static final String HOME = "home";
+
+ private BallerinaCliCommands() {
+ }
}
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java
index 17cb285e382e..f4b163040d58 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/LauncherUtils.java
@@ -47,7 +47,10 @@
*
* @since 0.8.0
*/
-public class LauncherUtils {
+public final class LauncherUtils {
+
+ private LauncherUtils() {
+ }
public static Path getSourceRootPath(String sourceRoot) {
// Get source root path.
@@ -84,8 +87,8 @@ public static BLauncherException createLauncherException(String errorMsg) {
public static BLauncherException createLauncherException(String errorPrefix, Throwable cause) {
String message;
- if (cause instanceof BError) {
- message = ((BError) cause).getPrintableStackTrace();
+ if (cause instanceof BError bError) {
+ message = bError.getPrintableStackTrace();
} else {
StringWriter sw = new StringWriter();
cause.printStackTrace(new PrintWriter(sw));
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/Main.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/Main.java
index 292f42f2bb0f..4b0d8a039e21 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/Main.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/Main.java
@@ -45,7 +45,8 @@
*
* @since 0.8.0
*/
-public class Main {
+public final class Main {
+
private static final String UNMATCHED_ARGUMENT_PREFIX = "Unmatched argument";
private static final String MISSING_REQUIRED_PARAMETER_PREFIX = "Missing required parameter";
private static final String COMPILATION_ERROR_MESSAGE = "compilation contains errors";
@@ -53,6 +54,9 @@ public class Main {
private static final PrintStream errStream = System.err;
private static final PrintStream outStream = System.out;
+ private Main() {
+ }
+
public static void main(String... args) {
try {
Optional optionalInvokedCmd = getInvokedCmd(args);
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BCompileUtil.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BCompileUtil.java
index 70e75a5df50f..d54baa503df6 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BCompileUtil.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BCompileUtil.java
@@ -26,7 +26,10 @@
*
* @since 0.94
*/
-public class BCompileUtil {
+public final class BCompileUtil {
+
+ private BCompileUtil() {
+ }
public static String readFileAsString(String path) throws IOException {
StringBuilder sb = new StringBuilder();
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java
index d0bce40181ea..d92abf44ff4e 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/launcher/util/BalToolsUtil.java
@@ -44,7 +44,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import static io.ballerina.cli.cmd.Constants.ADD_COMMAND;
@@ -96,7 +95,8 @@
*
* @since 2201.8.0
*/
-public class BalToolsUtil {
+public final class BalToolsUtil {
+
private static final String TOOL = "tool";
private static final String LIBS = "libs";
@@ -122,6 +122,9 @@ public class BalToolsUtil {
.resolve(REPOSITORIES_DIR).resolve(CENTRAL_REPOSITORY_CACHE_NAME)
.resolve(ProjectConstants.BALA_DIR_NAME);
+ private BalToolsUtil() {
+ }
+
public static boolean isNonBuiltInToolCommand(String commandName) {
return isToolCommand(commandName) && !builtInToolCommands.contains(commandName);
}
@@ -185,7 +188,7 @@ private static List getToolCommandJarAndDependencyJars(String commandName)
.resolve(TOOL).resolve(LIBS)
.toFile()))
.flatMap(List::stream)
- .collect(Collectors.toList());
+ .toList();
}
Optional toolOpt = balToolsManifest.getActiveTool(commandName);
@@ -276,7 +279,7 @@ public static void updateOldBalToolsToml() {
} catch (ProjectException ignore) {
return false;
}
- })).map(File::getName).collect(Collectors.toList());
+ })).map(File::getName).toList();
Optional latestVersion = getLatestVersion(versions);
versions.stream().forEach(version -> {
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateTestExecutableTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateTestExecutableTask.java
index 947e23792859..03a12e07f211 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateTestExecutableTask.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/CreateTestExecutableTask.java
@@ -43,6 +43,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -341,7 +342,7 @@ private void writeCmdArgsToFile(Path path, Target target, Path testSuiteJsonPath
// Write the cmdArgs to a file in path
Path writingPath = path.resolve(ProjectConstants.TEST_RUNTIME_MAIN_ARGS_FILE);
- try (BufferedWriter writer = java.nio.file.Files.newBufferedWriter(writingPath)) {
+ try (BufferedWriter writer = Files.newBufferedWriter(writingPath)) {
for (String arg : cmdArgs) {
writer.write(arg);
writer.newLine();
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBuildToolsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBuildToolsTask.java
index 75a5c96ff471..843b035b61d0 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBuildToolsTask.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunBuildToolsTask.java
@@ -368,6 +368,6 @@ private static List getToolCommandJarAndDependencyJars(List res
.resolve(TOOL).resolve(LIBS)
.toFile()))
.flatMap(List::stream)
- .collect(Collectors.toList());
+ .toList();
}
}
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunTestsTask.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunTestsTask.java
index 78c3a005a4ea..d6f54a96534d 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunTestsTask.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/task/RunTestsTask.java
@@ -54,7 +54,6 @@
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException;
@@ -336,7 +335,10 @@ public String getAgentCommand(Target target, Package currentPackage, Set
private List getAllSourceFilePaths(String projectRootString) throws IOException {
List sourceFilePaths = new ArrayList<>();
- List paths = Files.walk(Paths.get(projectRootString), 3).toList();
+ List paths;
+ try (Stream stream = Files.walk(Paths.get(projectRootString), 3)) {
+ paths = stream.toList();
+ }
if (isWindows) {
projectRootString = projectRootString.replace(PATH_SEPARATOR, EXCLUDES_PATTERN_PATH_SEPARATOR);
@@ -359,7 +361,7 @@ private List getAllSourceFilePaths(String projectRootString) throws IOExce
private static List filterPathStream(Stream pathStream, String combinedPattern) {
return pathStream.filter(
FileSystems.getDefault().getPathMatcher("glob:" + combinedPattern)::matches)
- .collect(Collectors.toList());
+ .toList();
}
private void getclassFromSourceFilePath(List sourcePatternList, Package currentPackage,
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/BrowserLauncher.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/BrowserLauncher.java
index 0172fa5c59a4..04304c3eb4a5 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/BrowserLauncher.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/BrowserLauncher.java
@@ -22,7 +22,7 @@
*
* @since 2.0.0
*/
-class BrowserLauncher {
+final class BrowserLauncher {
private BrowserLauncher() {
}
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/BuildUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/BuildUtils.java
index caab4d34c6de..a1da4720f8c8 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/BuildUtils.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/BuildUtils.java
@@ -28,7 +28,11 @@
* @since 2201.9.0
*/
-public class BuildUtils {
+public final class BuildUtils {
+
+ private BuildUtils() {
+ }
+
public static void notifyPlugins(Project project, Target target) {
ServiceLoader processorServiceLoader = ServiceLoader.load(CompilerPlugin.class);
for (CompilerPlugin plugin : processorServiceLoader) {
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/CentralUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/CentralUtils.java
index dc387b8d63d8..9383d241ce34 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/CentralUtils.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/CentralUtils.java
@@ -38,7 +38,7 @@
*
* @since 2.0.0
*/
-public class CentralUtils {
+public final class CentralUtils {
private static final String BALLERINA_CENTRAL_PRODUCTION_URL = "https://central.ballerina.io";
private static final String BALLERINA_CENTRAL_STAGING_URL = "https://staging-central.ballerina.io";
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/DebugUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/DebugUtils.java
index 340f367a9b40..66fc823ad664 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/DebugUtils.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/DebugUtils.java
@@ -10,12 +10,15 @@
*
* @since 2.0.0
*/
-public class DebugUtils {
+public final class DebugUtils {
private static final String DEBUG_ARGS_JAVA = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y";
private static final String JAVA_VERSION_PROP = "java.version";
private static final String COMPATIBLE_JRE_VERSION = "17";
+ private DebugUtils() {
+ }
+
/**
* Evaluates whether the ballerina program should be running on debug mode.
*
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/FileUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/FileUtils.java
index 18b6d2306cbb..552a6d71566e 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/FileUtils.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/FileUtils.java
@@ -36,7 +36,11 @@
*
* @since 2.0.0
*/
-public class FileUtils {
+public final class FileUtils {
+
+ private FileUtils() {
+ }
+
/**
* Get the name of the without the extension.
*
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java
index 3edf9219ddd5..83ac291c8730 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/GraalVMCompatibilityUtils.java
@@ -35,7 +35,10 @@
*
* @since 2201.7.0
*/
-public class GraalVMCompatibilityUtils {
+public final class GraalVMCompatibilityUtils {
+
+ private GraalVMCompatibilityUtils() {
+ }
private static boolean hasExternalPlatformDependencies(io.ballerina.projects.Package pkg) {
// Check if external platform dependencies are defined
diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/NativeUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/NativeUtils.java
index 97992829f6ae..2a4eae1000d1 100644
--- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/NativeUtils.java
+++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/NativeUtils.java
@@ -61,7 +61,6 @@
import java.util.Map;
import java.util.StringJoiner;
import java.util.jar.JarOutputStream;
-import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -89,7 +88,8 @@
*
* @since 2.3.0
*/
-public class NativeUtils {
+public final class NativeUtils {
+
private static final String MODULE_INIT_CLASS_NAME = "$_init";
private static final String TEST_EXEC_FUNCTION = "__execute__";
public static final String OS = System.getProperty("os.name").toLowerCase(Locale.getDefault());
@@ -109,6 +109,9 @@ public class NativeUtils {
"io.ballerina.runtime.api.values.BString"
});
+ private NativeUtils() {
+ }
+
//Add dynamically loading classes and methods to reflection config
public static void createReflectConfig(Path nativeConfigPath, Package currentPackage,
Map testSuiteMap) throws IOException {
@@ -169,9 +172,7 @@ public static void createReflectConfig(Path nativeConfigPath, Package currentPac
if (mockedFunctionClassFile.isFile()) {
BufferedReader br = Files.newBufferedReader(mockedFunctionClassPath, StandardCharsets.UTF_8);
Gson gsonRead = new Gson();
- Map testFileMockedFunctionMapping = gsonRead.fromJson(br,
- new TypeToken