Skip to content

Commit 6f4cefb

Browse files
turbanoffMandy Chung
authored and
Mandy Chung
committedSep 28, 2021
8274394: Use Optional.isEmpty instead of !Optional.isPresent in jdk.jlink
Reviewed-by: alanb, mchung
1 parent 94f5e80 commit 6f4cefb

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed
 

‎src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ protected void prepareApplicationFiles(ResourcePool imageContent) throws IOExcep
281281
if (mainClassName == null) {
282282
String path = "/" + module + "/module-info.class";
283283
Optional<ResourcePoolEntry> res = imageContent.findEntry(path);
284-
if (!res.isPresent()) {
284+
if (res.isEmpty()) {
285285
throw new IOException("module-info.class not found for " + module + " module");
286286
}
287287
ByteArrayInputStream stream = new ByteArrayInputStream(res.get().contentBytes());
@@ -293,8 +293,8 @@ protected void prepareApplicationFiles(ResourcePool imageContent) throws IOExcep
293293

294294
if (mainClassName != null) {
295295
// make sure main class exists!
296-
if (!imageContent.findEntry("/" + module + "/" +
297-
mainClassName.replace('.', '/') + ".class").isPresent()) {
296+
if (imageContent.findEntry("/" + module + "/" +
297+
mainClassName.replace('.', '/') + ".class").isEmpty()) {
298298
throw new IllegalArgumentException(module + " does not have main class: " + mainClassName);
299299
}
300300

‎src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ private JlinkConfiguration initJlinkConfig() throws BadArgs {
397397
}
398398

399399
ModuleFinder finder = newModuleFinder(options.modulePath, options.limitMods, roots);
400-
if (!finder.find("java.base").isPresent()) {
400+
if (finder.find("java.base").isEmpty()) {
401401
Path defModPath = getDefaultModulePath();
402402
if (defModPath != null) {
403403
options.modulePath.add(defModPath);
@@ -517,7 +517,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e)
517517

518518
private static Path toPathLocation(ResolvedModule m) {
519519
Optional<URI> ouri = m.reference().location();
520-
if (!ouri.isPresent())
520+
if (ouri.isEmpty())
521521
throw new InternalError(m + " does not have a location");
522522
URI uri = ouri.get();
523523
return Paths.get(uri);

‎src/jdk.jlink/share/classes/jdk/tools/jlink/internal/ResourcePoolManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class ResourcePoolManager {
5454
static Attributes readModuleAttributes(ResourcePoolModule mod) {
5555
String p = "/" + mod.name() + "/module-info.class";
5656
Optional<ResourcePoolEntry> content = mod.findEntry(p);
57-
if (!content.isPresent()) {
57+
if (content.isEmpty()) {
5858
throw new PluginException("module-info.class not found for " +
5959
mod.name() + " module");
6060
}

‎src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/LegalNoticeFilePlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private void dedupLegalNoticeEntry(ResourcePoolEntry entry) {
111111
.filter(e -> e.linkedTarget() == null)
112112
.filter(e -> Arrays.equals(e.contentBytes(), entry.contentBytes()))
113113
.findFirst();
114-
if (!otarget.isPresent()) {
114+
if (otarget.isEmpty()) {
115115
if (errorIfNotSameContent) {
116116
// all legal notices of the same file name are expected
117117
// to contain the same content

‎src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ private class Hasher {
890890
// filter modules resolved from the system module finder
891891
this.modules = config.modules().stream()
892892
.map(ResolvedModule::name)
893-
.filter(mn -> roots.contains(mn) && !system.find(mn).isPresent())
893+
.filter(mn -> roots.contains(mn) && system.find(mn).isEmpty())
894894
.collect(Collectors.toSet());
895895

896896
this.hashesBuilder = new ModuleHashesBuilder(config, modules);

0 commit comments

Comments
 (0)
Please sign in to comment.