fix sonar bug to call isPresent for Optional.
Fix for sonar bug:
@@ -22,6 +22,8 @@ import com.google.cloud.tools.jib.configuration.BuildContext;
import com.google.cloud.tools.jib.event.EventHandlers;
import com.google.cloud.tools.jib.image.json.ContainerConfigurationTemplate;
import com.google.common.base.Verify;
+import java.nio.file.Path;
+import java.util.Optional;
import java.util.Set;
/** Provides helper methods to check platforms. */
@@ -36,10 +38,10 @@ public class PlatformChecker {
static void checkManifestPlatform(
BuildContext buildContext, ContainerConfigurationTemplate containerConfig) {
EventHandlers eventHandlers = buildContext.getEventHandlers();
+ Optional<Path> path = buildContext.getBaseImageConfiguration().getTarPath();
String baseImageName =
- buildContext.getBaseImageConfiguration().getTarPath().isPresent()
- ? buildContext.getBaseImageConfiguration().getTarPath().get().toString()
- : buildContext.getBaseImageConfiguration().getImage().toString();
+ path.map(Path::toString)
+ .orElse(buildContext.getBaseImageConfiguration().getImage().toString());
Set<Platform> platforms = buildContext.getContainerConfiguration().getPlatforms();
Verify.verify(!platforms.isEmpty());
