Skip to content

Commit

Permalink
Fix some spotbugs errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow-Devil committed Oct 3, 2024
1 parent 0e1ae32 commit 6c3571f
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,29 +426,25 @@ public static void initPackageFromCentral(Path balaCache, Path projectPath, Stri
} catch (PackageAlreadyExistsException e) {
if (version == null) {
List<PackageVersion> 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<PackageVersion> 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<PackageVersion> 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);
}
Expand Down Expand Up @@ -1009,15 +1005,15 @@ private static void initToolPackage(Path path, String packageName) throws IOExce
}

@Nullable
private static PackageVersion findLatest(List<PackageVersion> packageVersions) {
private static Optional<PackageVersion> findLatest(List<PackageVersion> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ private static String otherPlatformGraalvmCompatibleVerified(String target,
private static Boolean isAllPlatformDepsGraalvmCompatible(Map<String, PackageManifest.Platform> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public Optional<TypeSymbol> transform(ExplicitNewExpressionNode node) {
instanceof BInvokableSymbol)) {
List<BVarSymbol> params = ((BInvokableSymbol) (((BLangInvocation) ((BLangTypeInit) bLangNode).
initInvocation).symbol)).params;
if (params.isEmpty()) {
if (params == null || params.isEmpty()) {
throw new IllegalStateException();
}

Expand Down Expand Up @@ -525,7 +525,7 @@ public Optional<TypeSymbol> transform(ImplicitNewExpressionNode node) {
}

List<BVarSymbol> params = ((BInvokableSymbol) initInvocation.symbol).params;
if (params.isEmpty()) {
if (params == null || params.isEmpty()) {
throw new IllegalStateException();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +16,7 @@
public class JarRepo implements Repo<Path> {
private final ZipConverter converter;

public JarRepo(@Nullable URI jarLocation) {
public JarRepo(URI jarLocation) {
this.converter = new ZipConverter(Paths.get(jarLocation));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import java.nio.file.Path;

import java.util.Objects;

/**
* This represents the standard Ballerina built-in system package repository provider.
*
Expand All @@ -34,7 +36,7 @@ public class TesterinaSystemPackageRepositoryProvider implements SystemPackageRe

@Override
public Repo<Path> loadRepository() {
return new JarRepo(SystemPackageRepositoryProvider.getClassUri(this));
return new JarRepo(Objects.requireNonNull(SystemPackageRepositoryProvider.getClassUri(this)));
}

}

0 comments on commit 6c3571f

Please sign in to comment.