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 12011c29e897..d82fc2e7079a 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 @@ -426,29 +426,25 @@ public static void initPackageFromCentral(Path balaCache, Path projectPath, Stri } catch (PackageAlreadyExistsException e) { if (version == null) { List packageVersions = getPackageVersions(pkgCacheParent); - PackageVersion latest = findLatest(packageVersions); - if (latest == null) { - // This is not supposed to execute - throw createLauncherException("unable to find package in the filesystem cache." + - " This is an unexpected error : " + e.getMessage()); - } + PackageVersion latest = findLatest(packageVersions).orElseThrow( + // This is not supposed to execute + () -> createLauncherException("unable to find package in the filesystem cache." + + " This is an unexpected error : " + e.getMessage())); version = latest.toString(); } } catch (CentralClientException e) { errStream.println("Warning: Unable to pull the package from Ballerina Central: " + e.getMessage()); if (findBalaTemplate(template, balaCache) == null) { List packageVersions = getPackageVersions(pkgCacheParent); - PackageVersion latest = findLatest(packageVersions); - if (latest == null) { - throw createLauncherException("template not found in filesystem cache."); - } + PackageVersion latest = findLatest(packageVersions).orElseThrow( + () -> createLauncherException("template not found in filesystem cache.")); version = latest.toString(); } } if (version == null) { List packageVersions = getPackageVersions(pkgCacheParent); - PackageVersion latest = findLatest(packageVersions); - version = Objects.requireNonNull(latest).toString(); + PackageVersion latest = findLatest(packageVersions).orElseThrow(); + version = latest.toString(); } applyTemplate(orgName, templatePackageName, version, packageName, projectPath, balaCache, filesInDir); } @@ -1009,15 +1005,15 @@ private static void initToolPackage(Path path, String packageName) throws IOExce } @Nullable - private static PackageVersion findLatest(List packageVersions) { + private static Optional findLatest(List packageVersions) { if (packageVersions.isEmpty()) { - return null; + return Optional.empty(); } PackageVersion latestVersion = packageVersions.get(0); for (PackageVersion pkgVersion : packageVersions) { latestVersion = getLatest(latestVersion, pkgVersion); } - return latestVersion; + return Optional.of(latestVersion); } private static PackageVersion getLatest(PackageVersion v1, PackageVersion v2) { 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 7e9ff9cff7c3..6fa94773f457 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 @@ -51,6 +51,7 @@ import java.nio.file.Path; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import static io.ballerina.cli.cmd.Constants.PULL_COMMAND; @@ -269,7 +270,7 @@ private String pullFromCentral(Settings settings, String orgName, String package private void pullFromMavenRepo(Settings settings, String orgName, String packageName, String version) { Repository targetRepository = null; for (Repository repository : settings.getRepositories()) { - if (repositoryName.equals(repository.id())) { + if (Objects.equals(repositoryName, repository.id())) { targetRepository = repository; break; } diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java index 7c02b07db963..755790bce5ea 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/cmd/PushCommand.java @@ -280,17 +280,17 @@ public void printUsage(StringBuilder out) { public void setParentCmdParser(CommandLine parentCmdParser) { } - private void pushPackage(@Nullable BuildProject project) { + private void pushPackage(BuildProject project) { Path balaFilePath = validateBalaFile(project, this.balaPath); pushBalaToCustomRepo(balaFilePath); } - private void pushPackage(@Nullable BuildProject project, MavenResolverClient client) { + private void pushPackage(BuildProject project, MavenResolverClient client) { Path balaFilePath = validateBalaFile(project, this.balaPath); pushBalaToCustomRepo(balaFilePath, client); } - private void pushPackage(@Nullable BuildProject project, CentralAPIClient client) + private void pushPackage(BuildProject project, CentralAPIClient client) throws CentralClientException { Path balaFilePath = validateBala(project, client, this.balaPath); pushBalaToRemote(balaFilePath, client); 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 03a12e07f211..d22864275cf3 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 @@ -171,6 +171,9 @@ private void standaloneFatJarGeneration(Project project, JBallerinaBackend jBall for (ModuleDescriptor moduleDescriptor : project.currentPackage().moduleDependencyGraph().toTopologicallySortedList()) { Module module = project.currentPackage().module(moduleDescriptor.name()); + if (module == null) { + throw createLauncherException("module not found: " + moduleDescriptor.name()); + } testExecDependencies.addAll(jBallerinaBackend.jarResolver() .getJarFilePathsRequiredForTestExecution(module.moduleName()) ); 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 bacc8855d0e4..f1162595088b 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 @@ -66,9 +66,10 @@ private static String otherPlatformGraalvmCompatibleVerified(String target, private static Boolean isAllPlatformDepsGraalvmCompatible(Map platforms) { Boolean isAllDepsGraalvmCompatible = true; for (PackageManifest.Platform platform: platforms.values()) { - if (platform.isPlatfromDepsGraalvmCompatible() == null) { + Boolean graalvmCompatible = platform.graalvmCompatible(); + if (graalvmCompatible == null) { isAllDepsGraalvmCompatible = null; - } else if (!platform.isPlatfromDepsGraalvmCompatible()) { + } else if (!graalvmCompatible) { return false; } } diff --git a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java index 2b322b78b592..8720b267e32f 100644 --- a/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java +++ b/cli/ballerina-cli/src/main/java/io/ballerina/cli/utils/TestUtils.java @@ -303,6 +303,9 @@ public static boolean createTestSuitesForProject(Project project, Target target, for (ModuleDescriptor moduleDescriptor : project.currentPackage().moduleDependencyGraph().toTopologicallySortedList()) { Module module = project.currentPackage().module(moduleDescriptor.name()); + if (module == null) { + throw new IllegalStateException("Module is not found in the package: " + moduleDescriptor.name()); + } ModuleName moduleName = module.moduleName(); TestSuite suite = testProcessor.testSuite(module).orElse(null); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/EnvironmentResolver.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/EnvironmentResolver.java index a39cc3746b01..27042c3a10f7 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/EnvironmentResolver.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/EnvironmentResolver.java @@ -304,8 +304,8 @@ && isNarrowerEnclosure(exprFuncBody.getPosition())) { @Override public void visit(BLangSimpleVariableDef varDefNode) { - boolean isFuture = varDefNode.getVariable().expr != null - && varDefNode.getVariable().expr.getBType() instanceof BFutureType; + BLangExpression expr = varDefNode.getVariable().expr; + boolean isFuture = expr != null && expr.getBType() instanceof BFutureType; if (isFuture) { return; } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java index c19429826ce3..7c49201c0e7b 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/compiler/api/impl/ExpectedTypeFinder.java @@ -473,7 +473,7 @@ public Optional transform(ExplicitNewExpressionNode node) { instanceof BInvokableSymbol)) { List params = ((BInvokableSymbol) (((BLangInvocation) ((BLangTypeInit) bLangNode). initInvocation).symbol)).params; - if (params.isEmpty()) { + if (params == null || params.isEmpty()) { throw new IllegalStateException(); } @@ -525,7 +525,7 @@ public Optional transform(ImplicitNewExpressionNode node) { } List params = ((BInvokableSymbol) initInvocation.symbol).params; - if (params.isEmpty()) { + if (params == null || params.isEmpty()) { throw new IllegalStateException(); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/JarRepo.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/JarRepo.java index f5668a87edc3..cf449f01fe81 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/JarRepo.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/repo/JarRepo.java @@ -1,7 +1,6 @@ package org.wso2.ballerinalang.compiler.packaging.repo; import org.ballerinalang.model.elements.PackageID; -import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.packaging.Patten; import org.wso2.ballerinalang.compiler.packaging.converters.Converter; import org.wso2.ballerinalang.compiler.packaging.converters.ZipConverter; @@ -17,7 +16,7 @@ public class JarRepo implements Repo { private final ZipConverter converter; - public JarRepo(@Nullable URI jarLocation) { + public JarRepo(URI jarLocation) { this.converter = new ZipConverter(Paths.get(jarLocation)); } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java index b83114a0ff14..8c23828e3e56 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/Types.java @@ -30,6 +30,7 @@ import org.ballerinalang.model.types.TypeKind; import org.ballerinalang.util.BLangCompilerConstants; import org.ballerinalang.util.diagnostic.DiagnosticErrorCode; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; import org.wso2.ballerinalang.compiler.diagnostic.BLangDiagnosticLog; import org.wso2.ballerinalang.compiler.parser.BLangAnonymousModelHelper; @@ -1505,7 +1506,7 @@ public boolean isInherentlyImmutableType(BType type) { * @return the implied type if provided with a type reference type or an intersection type, * else returns the original type */ - @Nullable + @Contract("null -> null; !null -> !null") public static BType getImpliedType(@Nullable BType type) { type = getReferredType(type); if (type != null && type.tag == TypeTags.INTERSECTION) { @@ -1515,7 +1516,7 @@ public static BType getImpliedType(@Nullable BType type) { return type; } - @Nullable + @Contract("null -> null; !null -> !null") public static BType getReferredType(BType type) { if (type != null && type.tag == TypeTags.TYPEREFDESC) { return getReferredType(((BTypeReferenceType) type).referredType); diff --git a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java index 5829f91d5bb3..20a54b54bafd 100644 --- a/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java +++ b/misc/testerina/modules/testerina-core/src/main/java/org/ballerinalang/testerina/TesterinaSystemPackageRepositoryProvider.java @@ -24,6 +24,8 @@ import java.nio.file.Path; +import java.util.Objects; + /** * This represents the standard Ballerina built-in system package repository provider. * @@ -34,7 +36,7 @@ public class TesterinaSystemPackageRepositoryProvider implements SystemPackageRe @Override public Repo loadRepository() { - return new JarRepo(SystemPackageRepositoryProvider.getClassUri(this)); + return new JarRepo(Objects.requireNonNull(SystemPackageRepositoryProvider.getClassUri(this))); } }