8274394: Use Optional.isEmpty instead of !Optional.isPresent in jdk.jlink

Reviewed-by: alanb, mchung
This commit is contained in:
Andrey Turbanov 2021-09-28 17:22:27 +00:00 committed by Mandy Chung
parent 94f5e807c9
commit 6f4cefbcba
5 changed files with 8 additions and 8 deletions

View File

@ -281,7 +281,7 @@ public final class DefaultImageBuilder implements ImageBuilder {
if (mainClassName == null) {
String path = "/" + module + "/module-info.class";
Optional<ResourcePoolEntry> res = imageContent.findEntry(path);
if (!res.isPresent()) {
if (res.isEmpty()) {
throw new IOException("module-info.class not found for " + module + " module");
}
ByteArrayInputStream stream = new ByteArrayInputStream(res.get().contentBytes());
@ -293,8 +293,8 @@ public final class DefaultImageBuilder implements ImageBuilder {
if (mainClassName != null) {
// make sure main class exists!
if (!imageContent.findEntry("/" + module + "/" +
mainClassName.replace('.', '/') + ".class").isPresent()) {
if (imageContent.findEntry("/" + module + "/" +
mainClassName.replace('.', '/') + ".class").isEmpty()) {
throw new IllegalArgumentException(module + " does not have main class: " + mainClassName);
}

View File

@ -397,7 +397,7 @@ public class JlinkTask {
}
ModuleFinder finder = newModuleFinder(options.modulePath, options.limitMods, roots);
if (!finder.find("java.base").isPresent()) {
if (finder.find("java.base").isEmpty()) {
Path defModPath = getDefaultModulePath();
if (defModPath != null) {
options.modulePath.add(defModPath);
@ -517,7 +517,7 @@ public class JlinkTask {
private static Path toPathLocation(ResolvedModule m) {
Optional<URI> ouri = m.reference().location();
if (!ouri.isPresent())
if (ouri.isEmpty())
throw new InternalError(m + " does not have a location");
URI uri = ouri.get();
return Paths.get(uri);

View File

@ -54,7 +54,7 @@ public class ResourcePoolManager {
static Attributes readModuleAttributes(ResourcePoolModule mod) {
String p = "/" + mod.name() + "/module-info.class";
Optional<ResourcePoolEntry> content = mod.findEntry(p);
if (!content.isPresent()) {
if (content.isEmpty()) {
throw new PluginException("module-info.class not found for " +
mod.name() + " module");
}

View File

@ -111,7 +111,7 @@ public final class LegalNoticeFilePlugin extends AbstractPlugin {
.filter(e -> e.linkedTarget() == null)
.filter(e -> Arrays.equals(e.contentBytes(), entry.contentBytes()))
.findFirst();
if (!otarget.isPresent()) {
if (otarget.isEmpty()) {
if (errorIfNotSameContent) {
// all legal notices of the same file name are expected
// to contain the same content

View File

@ -890,7 +890,7 @@ public class JmodTask {
// filter modules resolved from the system module finder
this.modules = config.modules().stream()
.map(ResolvedModule::name)
.filter(mn -> roots.contains(mn) && !system.find(mn).isPresent())
.filter(mn -> roots.contains(mn) && system.find(mn).isEmpty())
.collect(Collectors.toSet());
this.hashesBuilder = new ModuleHashesBuilder(config, modules);