--- old/src/java.base/share/classes/java/lang/NamedPackage.java 2016-04-25 14:50:24.000000000 -0700 +++ new/src/java.base/share/classes/java/lang/NamedPackage.java 2016-04-25 14:50:24.000000000 -0700 @@ -75,7 +75,7 @@ if (module.isNamed() && module.getLayer() != null) { Configuration cf = module.getLayer().configuration(); ModuleReference mref - = cf.findModule(module.getName()).get().reference(); + = cf.findModule(module.getName()).getWhenPresent().reference(); return mref.location().orElse(null); } return null; --- old/src/java.base/share/classes/java/lang/invoke/MethodHandles.java 2016-04-25 14:50:25.000000000 -0700 +++ new/src/java.base/share/classes/java/lang/invoke/MethodHandles.java 2016-04-25 14:50:25.000000000 -0700 @@ -4822,7 +4822,7 @@ return longest.size() == 0 ? empty : longest.subList(cpSize, longest.size()); } else { return nonNullInits.stream().map(MethodHandle::type).map(MethodType::parameterList). - reduce((p, q) -> p.size() >= q.size() ? p : q).get(); + reduce((p, q) -> p.size() >= q.size() ? p : q).getWhenPresent(); } } --- old/src/java.base/share/classes/java/lang/module/ModuleFinder.java 2016-04-25 14:50:27.000000000 -0700 +++ new/src/java.base/share/classes/java/lang/module/ModuleFinder.java 2016-04-25 14:50:27.000000000 -0700 @@ -329,7 +329,7 @@ .map(a -> a.descriptor().name()) .distinct() .map(this::find) - .map(Optional::get) + .map(Optional::getWhenPresent) .collect(Collectors.toSet()); } return allModules; --- old/src/java.base/share/classes/java/lang/module/ModulePath.java 2016-04-25 14:50:29.000000000 -0700 +++ new/src/java.base/share/classes/java/lang/module/ModulePath.java 2016-04-25 14:50:29.000000000 -0700 @@ -438,8 +438,7 @@ // map names of service configuration files to service names Set serviceNames = configFiles.stream() .map(this::toServiceName) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .collect(Collectors.toSet()); // parse each service configuration file --- old/src/java.base/share/classes/java/lang/module/ModuleReader.java 2016-04-25 14:50:31.000000000 -0700 +++ new/src/java.base/share/classes/java/lang/module/ModuleReader.java 2016-04-25 14:50:30.000000000 -0700 @@ -102,7 +102,7 @@ default Optional open(String name) throws IOException { Optional ouri = find(name); if (ouri.isPresent()) { - return Optional.of(ouri.get().toURL().openStream()); + return Optional.of(ouri.getWhenPresent().toURL().openStream()); } else { return Optional.empty(); } @@ -144,7 +144,7 @@ default Optional read(String name) throws IOException { Optional in = open(name); if (in.isPresent()) { - byte[] bytes = in.get().readAllBytes(); + byte[] bytes = in.getWhenPresent().readAllBytes(); return Optional.of(ByteBuffer.wrap(bytes)); } else { return Optional.empty(); --- old/src/java.base/share/classes/java/lang/module/Resolver.java 2016-04-25 14:50:32.000000000 -0700 +++ new/src/java.base/share/classes/java/lang/module/Resolver.java 2016-04-25 14:50:32.000000000 -0700 @@ -98,7 +98,7 @@ if (TRACE) { trace("Root module %s located", root); if (mref.location().isPresent()) - trace(" (%s)", mref.location().get()); + trace(" (%s)", mref.location().getWhenPresent()); } assert mref.descriptor().name().equals(root); @@ -157,7 +157,7 @@ trace("Module %s located, required by %s", dn, descriptor.name()); if (mref.location().isPresent()) - trace(" (%s)", mref.location().get()); + trace(" (%s)", mref.location().getWhenPresent()); } } @@ -232,7 +232,7 @@ if (!nameToReference.containsKey(pn)) { if (TRACE && mref.location().isPresent()) - trace(" (%s)", mref.location().get()); + trace(" (%s)", mref.location().getWhenPresent()); nameToReference.put(pn, mref); q.push(provider); @@ -434,7 +434,7 @@ Optional ohashes = descriptor.hashes(); if (!ohashes.isPresent()) continue; - Hasher.DependencyHashes hashes = ohashes.get(); + Hasher.DependencyHashes hashes = ohashes.getWhenPresent(); // check dependences for (ModuleDescriptor.Requires d : descriptor.requires()) { --- old/src/java.base/share/classes/java/lang/reflect/Layer.java 2016-04-25 14:50:33.000000000 -0700 +++ new/src/java.base/share/classes/java/lang/reflect/Layer.java 2016-04-25 14:50:33.000000000 -0700 @@ -362,7 +362,7 @@ Objects.requireNonNull(cf); Optional oparent = cf.parent(); - if (!oparent.isPresent() || oparent.get() != this.configuration()) { + if (!oparent.isPresent() || oparent.getWhenPresent() != this.configuration()) { throw new IllegalArgumentException( "Parent of configuration != configuration of this Layer"); } @@ -520,7 +520,7 @@ return m.getClassLoader(); Optional ol = parent(); if (ol.isPresent()) - return ol.get().findLoader(name); + return ol.getWhenPresent().findLoader(name); throw new IllegalArgumentException("Module " + name + " not known to this layer"); } --- old/src/java.base/share/classes/java/lang/reflect/Module.java 2016-04-25 14:50:35.000000000 -0700 +++ new/src/java.base/share/classes/java/lang/reflect/Module.java 2016-04-25 14:50:34.000000000 -0700 @@ -896,7 +896,7 @@ while (layer != null) { if (layer.configuration() == cf) { Optional om = layer.findModule(dn); - m = om.get(); + m = om.getWhenPresent(); assert m.getLayer() == layer; break; } --- old/src/java.base/share/classes/java/util/Optional.java 2016-04-25 14:50:36.000000000 -0700 +++ new/src/java.base/share/classes/java/util/Optional.java 2016-04-25 14:50:36.000000000 -0700 @@ -126,14 +126,46 @@ } /** + * Equivalent to {@link #getWhenPresent()}. * If a value is present, returns the value, otherwise throws * {@code NoSuchElementException}. * + * @deprecated + * This method's simple name {@code get} makes it the obvious method to + * call to retrieve the value from this {@code Optional}. However, it has + * no mechanism to avoid an exception if this {@code Optional} is empty. + * This tends to lead to code that mishandles empty {@code Optional} + * values. Consider using other methods that handle the case where + * the {@code Optional} might be empty, such as + * {@link #filter(java.util.function.Predicate) filter()}, + * {@link #map(java.util.function.Function) map()}, + * {@link #ifPresent(java.util.function.Consumer) ifPresent()} + * and related methods, and + * {@link #orElse(java.lang.Object) orElse()} and related methods. + * Use {@link getWhenPresent()} when it is known that a value is + * always present. + * * @return the non-{@code null} value described by this {@code Optional} * @throws NoSuchElementException if no value is present * @see Optional#isPresent() */ + @Deprecated(since="9") public T get() { + return getWhenPresent(); + } + + /** + * If a value is present, returns the value, otherwise throws + * {@code NoSuchElementException}. + * + * @apiNote + * Use this method only when it is known that a value is always present. + * + * @return the non-{@code null} value described by this {@code Optional} + * @throws NoSuchElementException if no value is present + * @see Optional#isPresent() + */ + public T getWhenPresent() { if (value == null) { throw new NoSuchElementException("No value present"); } --- old/src/java.base/share/classes/java/util/OptionalDouble.java 2016-04-25 14:50:37.000000000 -0700 +++ new/src/java.base/share/classes/java/util/OptionalDouble.java 2016-04-25 14:50:37.000000000 -0700 @@ -110,10 +110,24 @@ * If a value is present, returns the value, otherwise throws * {@code NoSuchElementException}. * + * @deprecated + * This method's name {@code getAsDouble} makes it the obvious method to + * call to retrieve the value from this {@code OptionalDouble}. However, it has + * no mechanism to avoid an exception if this {@code OptionalDouble} is empty. + * This tends to lead to code that mishandles empty {@code OptionalDouble} + * values. Consider using other methods that handle the case where + * the {@code OptionalDouble} might be empty, such as + * {@link #ifPresent(java.util.function.DoubleConsumer) ifPresent()} + * and related methods, and + * {@link #orElse(double) orElse()} and related methods. + * Use {@link getWhenPresent()} when it is known that a value is + * always present. + * * @return the value described by this {@code OptionalDouble} * @throws NoSuchElementException if no value is present * @see OptionalDouble#isPresent() */ + @Deprecated(since="9") public double getAsDouble() { if (!isPresent) { throw new NoSuchElementException("No value present"); @@ -122,6 +136,24 @@ } /** + * If a value is present, returns the value, otherwise throws + * {@code NoSuchElementException}. + * + * @apiNote + * Use this method only when it is known that a value is always present. + * + * @return the value described by this {@code OptionalDouble} + * @throws NoSuchElementException if no value is present + * @see OptionalDouble#isPresent() + */ + public double getWhenPresent() { + if (!isPresent) { + throw new NoSuchElementException("No value present"); + } + return value; + } + + /** * If a value is present, returns {@code true}, otherwise {@code false}. * * @return {@code true} if a value is present, otherwise {@code false} --- old/src/java.base/share/classes/java/util/OptionalInt.java 2016-04-25 14:50:38.000000000 -0700 +++ new/src/java.base/share/classes/java/util/OptionalInt.java 2016-04-25 14:50:38.000000000 -0700 @@ -107,14 +107,44 @@ } /** + * Equivalent to {@link #getWhenPresent()}. * If a value is present, returns the value, otherwise throws * {@code NoSuchElementException}. * + * @deprecated + * This method's name {@code getAsInt} makes it the obvious method to + * call to retrieve the value from this {@code OptionalInt}. However, it has + * no mechanism to avoid an exception if this {@code OptionalInt} is empty. + * This tends to lead to code that mishandles empty {@code OptionalInt} + * values. Consider using other methods that handle the case where + * the {@code OptionalInt} might be empty, such as + * {@link #ifPresent(java.util.function.IntConsumer) ifPresent()} + * and related methods, and + * {@link #orElse(int) orElse()} and related methods. + * Use {@link getWhenPresent()} when it is known that a value is + * always present. + * * @return the value described by this {@code OptionalInt} * @throws NoSuchElementException if no value is present * @see OptionalInt#isPresent() */ + @Deprecated(since="9") public int getAsInt() { + return getWhenPresent(); + } + + /** + * If a value is present, returns the value, otherwise throws + * {@code NoSuchElementException}. + * + * @apiNote + * Use this method only when it is known that a value is always present. + * + * @return the value described by this {@code OptionalInt} + * @throws NoSuchElementException if no value is present + * @see OptionalInt#isPresent() + */ + public int getWhenPresent() { if (!isPresent) { throw new NoSuchElementException("No value present"); } --- old/src/java.base/share/classes/java/util/OptionalLong.java 2016-04-25 14:50:40.000000000 -0700 +++ new/src/java.base/share/classes/java/util/OptionalLong.java 2016-04-25 14:50:39.000000000 -0700 @@ -107,13 +107,28 @@ } /** + * Equivalent to {@link #getWhenPresent()}. * If a value is present, returns the value, otherwise throws * {@code NoSuchElementException}. * + * @deprecated + * This method's name {@code getAsLong} makes it the obvious method to + * call to retrieve the value from this {@code OptionalLong}. However, it has + * no mechanism to avoid an exception if this {@code OptionalLong} is empty. + * This tends to lead to code that mishandles empty {@code OptionalLong} + * values. Consider using other methods that handle the case where + * the {@code OptionalLong} might be empty, such as + * {@link #ifPresent(java.util.function.LongConsumer) ifPresent()} + * and related methods, and + * {@link #orElse(long) orElse()} and related methods. + * Use {@link getWhenPresent()} when it is known that a value is + * always present. + * * @return the value described by this {@code OptionalLong} * @throws NoSuchElementException if no value is present * @see OptionalLong#isPresent() */ + @Deprecated(since="9") public long getAsLong() { if (!isPresent) { throw new NoSuchElementException("No value present"); @@ -122,6 +137,24 @@ } /** + * If a value is present, returns the value, otherwise throws + * {@code NoSuchElementException}. + * + * @apiNote + * Use this method only when it is known that a value is always present. + * + * @return the value described by this {@code OptionalLong} + * @throws NoSuchElementException if no value is present + * @see OptionalLong#isPresent() + */ + public long getWhenPresent() { + if (!isPresent) { + throw new NoSuchElementException("No value present"); + } + return value; + } + + /** * If a value is present, returns {@code true}, otherwise {@code false}. * * @return {@code true} if a value is present, otherwise {@code false} --- old/src/java.base/share/classes/java/util/ServiceLoader.java 2016-04-25 14:50:41.000000000 -0700 +++ new/src/java.base/share/classes/java/util/ServiceLoader.java 2016-04-25 14:50:41.000000000 -0700 @@ -600,7 +600,7 @@ if (descriptorIterator.hasNext()) { ModuleDescriptor descriptor = descriptorIterator.next(); - nextModule = currentLayer.findModule(descriptor.name()).get(); + nextModule = currentLayer.findModule(descriptor.name()).getWhenPresent(); Provides provides = descriptor.provides().get(serviceName); providersIterator = provides.providers().iterator(); --- old/src/java.base/share/classes/jdk/Version.java 2016-04-25 14:50:42.000000000 -0700 +++ new/src/java.base/share/classes/jdk/Version.java 2016-04-25 14:50:42.000000000 -0700 @@ -459,8 +459,8 @@ } else { if (!oPre.isPresent()) return -1; - String val = pre.get(); - String oVal = oPre.get(); + String val = pre.getWhenPresent(); + String oVal = oPre.getWhenPresent(); if (val.matches("\\d+")) { return (oVal.matches("\\d+") ? (new BigInteger(val)).compareTo(new BigInteger(oVal)) @@ -478,7 +478,7 @@ Optional oBuild = ob.build(); if (oBuild.isPresent()) { return (build.isPresent() - ? build.get().compareTo(oBuild.get()) + ? build.getWhenPresent().compareTo(oBuild.getWhenPresent()) : 1); } else if (build.isPresent()) { return -1; @@ -494,7 +494,7 @@ } else { if (!oOpt.isPresent()) return 1; - return optional.get().compareTo(oOpt.get()); + return optional.getWhenPresent().compareTo(oOpt.getWhenPresent()); } return 0; } @@ -513,13 +513,13 @@ pre.ifPresent(v -> sb.append("-").append(v)); if (build.isPresent()) { - sb.append("+").append(build.get()); + sb.append("+").append(build.getWhenPresent()); if (optional.isPresent()) - sb.append("-").append(optional.get()); + sb.append("-").append(optional.getWhenPresent()); } else { if (optional.isPresent()) { sb.append(pre.isPresent() ? "-" : "+-"); - sb.append(optional.get()); + sb.append(optional.getWhenPresent()); } } --- old/src/java.base/share/classes/jdk/internal/loader/BootLoader.java 2016-04-25 14:50:44.000000000 -0700 +++ new/src/java.base/share/classes/jdk/internal/loader/BootLoader.java 2016-04-25 14:50:44.000000000 -0700 @@ -239,7 +239,7 @@ Optional om = Layer.boot().findModule(mn); if (!om.isPresent()) throw new InternalError(mn + " not in boot layer"); - return om.get(); + return om.getWhenPresent(); } return null; --- old/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java 2016-04-25 14:50:45.000000000 -0700 +++ new/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java 2016-04-25 14:50:45.000000000 -0700 @@ -115,7 +115,7 @@ URL url = null; if (mref.location().isPresent()) { try { - url = mref.location().get().toURL(); + url = mref.location().getWhenPresent().toURL(); } catch (MalformedURLException e) { } } this.loader = loader; --- old/src/java.base/share/classes/jdk/internal/loader/Loader.java 2016-04-25 14:50:46.000000000 -0700 +++ new/src/java.base/share/classes/jdk/internal/loader/Loader.java 2016-04-25 14:50:46.000000000 -0700 @@ -117,7 +117,7 @@ URL url = null; if (mref.location().isPresent()) { try { - url = mref.location().get().toURL(); + url = mref.location().getWhenPresent().toURL(); } catch (MalformedURLException e) { } } this.mref = mref; @@ -205,7 +205,7 @@ for (String name : nameToModule.keySet()) { - ResolvedModule resolvedModule = cf.findModule(name).get(); + ResolvedModule resolvedModule = cf.findModule(name).getWhenPresent(); assert resolvedModule.configuration() == cf; for (ResolvedModule other : resolvedModule.reads()) { @@ -307,7 +307,7 @@ Optional ouri = moduleReaderFor(mref).find(name); if (ouri.isPresent()) { try { - return ouri.get().toURL(); + return ouri.getWhenPresent().toURL(); } catch (MalformedURLException e) { } } return null; --- old/src/java.base/share/classes/jdk/internal/logger/SimpleConsoleLogger.java 2016-04-25 14:50:47.000000000 -0700 +++ new/src/java.base/share/classes/jdk/internal/logger/SimpleConsoleLogger.java 2016-04-25 14:50:47.000000000 -0700 @@ -192,7 +192,7 @@ private String getCallerInfo() { Optional frame = new CallerFinder().get(); if (frame.isPresent()) { - return frame.get().getClassName() + " " + frame.get().getMethodName(); + return frame.getWhenPresent().getClassName() + " " + frame.getWhenPresent().getMethodName(); } else { return name; } --- old/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java 2016-04-25 14:50:49.000000000 -0700 +++ new/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java 2016-04-25 14:50:48.000000000 -0700 @@ -104,7 +104,7 @@ Optional obase = systemModulePath.find(JAVA_BASE); if (!obase.isPresent()) throw new InternalError(JAVA_BASE + " not found"); - ModuleReference base = obase.get(); + ModuleReference base = obase.getWhenPresent(); BootLoader.loadModule(base); Modules.defineModule(null, base.descriptor(), base.location().orElse(null)); @@ -306,7 +306,7 @@ for (String mod : otherMods) { Optional omref = finder.find(mod); if (omref.isPresent()) { - ModuleReference mref = omref.get(); + ModuleReference mref = omref.getWhenPresent(); map.putIfAbsent(mod, mref); mrefs.add(mref); } else { @@ -362,7 +362,7 @@ Optional om = bootLayer.findModule(mn); if (!om.isPresent()) fail("Unknown module: " + mn); - Module m = om.get(); + Module m = om.getWhenPresent(); // the value is the set of other modules (by name) for (String name : e.getValue()) { @@ -374,7 +374,7 @@ om = bootLayer.findModule(name); if (!om.isPresent()) fail("Unknown module: " + name); - other = om.get(); + other = om.getWhenPresent(); } Modules.addReads(m, other); @@ -408,7 +408,7 @@ Optional om = bootLayer.findModule(mn); if (!om.isPresent()) fail("Unknown module: " + mn); - m = om.get(); + m = om.getWhenPresent(); // the value is the set of modules to export to (by name) for (String name : e.getValue()) { @@ -419,7 +419,7 @@ } else { om = bootLayer.findModule(name); if (om.isPresent()) { - other = om.get(); + other = om.getWhenPresent(); } else { fail("Unknown module: " + name); } --- old/src/java.base/share/classes/jdk/internal/module/ModuleInfoWriter.java 2016-04-25 14:50:50.000000000 -0700 +++ new/src/java.base/share/classes/jdk/internal/module/ModuleInfoWriter.java 2016-04-25 14:50:50.000000000 -0700 @@ -61,11 +61,11 @@ Optional oversion = descriptor.version(); if (oversion.isPresent()) - cw.visitAttribute(new VersionAttribute(oversion.get())); + cw.visitAttribute(new VersionAttribute(oversion.getWhenPresent())); Optional omain = descriptor.mainClass(); if (omain.isPresent()) - cw.visitAttribute(new MainClassAttribute(omain.get())); + cw.visitAttribute(new MainClassAttribute(omain.getWhenPresent())); // write the TargetPlatform attribute if have any of OS name/arch/version String osName = descriptor.osName().orElse(null); --- old/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java 2016-04-25 14:50:51.000000000 -0700 +++ new/src/java.base/share/classes/jdk/internal/module/ModulePatcher.java 2016-04-25 14:50:51.000000000 -0700 @@ -274,7 +274,7 @@ try { Optional ouri = mref.location(); if (ouri.isPresent()) - return ouri.get().toURL(); + return ouri.getWhenPresent().toURL(); } catch (MalformedURLException e) { } return null; } --- old/src/java.base/share/classes/sun/launcher/LauncherHelper.java 2016-04-25 14:50:52.000000000 -0700 +++ new/src/java.base/share/classes/sun/launcher/LauncherHelper.java 2016-04-25 14:50:52.000000000 -0700 @@ -529,7 +529,7 @@ // should not happen throw new InternalError("Module " + mainModule + " not in boot Layer"); } - Module m = om.get(); + Module m = om.getWhenPresent(); // get main class if (mainClass == null) { @@ -537,7 +537,7 @@ if (!omc.isPresent()) { abort(null, "java.launcher.module.error1", mainModule); } - mainClass = omc.get(); + mainClass = omc.getWhenPresent(); } // load the class from the module @@ -816,7 +816,7 @@ } // load the FX launcher class - fxLauncherClass = Class.forName(om.get(), JAVAFX_LAUNCHER_CLASS_NAME); + fxLauncherClass = Class.forName(om.getWhenPresent(), JAVAFX_LAUNCHER_CLASS_NAME); if (fxLauncherClass == null) { abort(null, "java.launcher.cls.error5"); } --- old/src/java.logging/share/classes/java/util/logging/LogManager.java 2016-04-25 14:50:54.000000000 -0700 +++ new/src/java.logging/share/classes/java/util/logging/LogManager.java 2016-04-25 14:50:53.000000000 -0700 @@ -2104,7 +2104,7 @@ } if (loggers.isEmpty()) continue; for (String pk : properties) { - ConfigProperty cp = ConfigProperty.find(pk).get(); + ConfigProperty cp = ConfigProperty.find(pk).getWhenPresent(); String p = previous.getProperty(pk, null); String n = next.getProperty(pk, null); --- old/src/java.management/share/classes/java/lang/management/ManagementFactory.java 2016-04-25 14:50:55.000000000 -0700 +++ new/src/java.management/share/classes/java/lang/management/ManagementFactory.java 2016-04-25 14:50:55.000000000 -0700 @@ -943,7 +943,7 @@ .findFirst(); if (op.isPresent()) { - return op.get(); + return op.getWhenPresent(); } else { return null; } @@ -966,7 +966,7 @@ } }); - PlatformComponent singleton = op.isPresent() ? op.get() : null; + PlatformComponent singleton = op.isPresent() ? op.getWhenPresent() : null; if (singleton == null) { throw new IllegalArgumentException(mbeanIntf.getName() + " is not a platform management interface"); --- old/src/jdk.jartool/share/classes/sun/tools/jar/Main.java 2016-04-25 14:50:56.000000000 -0700 +++ new/src/jdk.jartool/share/classes/sun/tools/jar/Main.java 2016-04-25 14:50:56.000000000 -0700 @@ -1681,7 +1681,7 @@ Optional mc = md.mainClass(); if (mc.isPresent()) - sb.append("\nMain class:\n " + mc.get()); + sb.append("\nMain class:\n " + mc.getWhenPresent()); s = md.conceals(); if (!s.isEmpty()) { @@ -1696,7 +1696,7 @@ (Optional) m.invoke(md); if (optHashes.isPresent()) { - Hasher.DependencyHashes hashes = optHashes.get(); + Hasher.DependencyHashes hashes = optHashes.getWhenPresent(); sb.append("\nHashes:"); sb.append("\n Algorithm: " + hashes.algorithm()); hashes.names().stream().forEach(mod -> @@ -1805,7 +1805,7 @@ if (!omref.isPresent()) { throw new IOException(formatMsg2("error.hash.dep", name , dn)); } - map.put(dn, modRefToPath(omref.get())); + map.put(dn, modRefToPath(omref.getWhenPresent())); } } @@ -1817,7 +1817,7 @@ } private static Path modRefToPath(ModuleReference mref) { - URI location = mref.location().get(); + URI location = mref.location().getWhenPresent(); return Paths.get(location); } } --- old/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java 2016-04-25 14:50:58.000000000 -0700 +++ new/src/jdk.jlink/share/classes/jdk/tools/jlink/builder/DefaultImageBuilder.java 2016-04-25 14:50:57.000000000 -0700 @@ -223,7 +223,7 @@ .append("\n"); sb.append("$DIR/java $JLINK_VM_OPTIONS -m ") .append(module).append('/') - .append(mainClass.get()) + .append(mainClass.getWhenPresent()) .append(" $@\n"); try (BufferedWriter writer = Files.newBufferedWriter(cmd, --- old/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java 2016-04-25 14:50:59.000000000 -0700 +++ new/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/JlinkTask.java 2016-04-25 14:50:59.000000000 -0700 @@ -242,7 +242,7 @@ Map modPaths = new HashMap<>(); for (ResolvedModule resolvedModule : cf.modules()) { ModuleReference mref = resolvedModule.reference(); - URI uri = mref.location().get(); + URI uri = mref.location().getWhenPresent(); modPaths.put(mref.descriptor().name(), Paths.get(uri)); } return modPaths; @@ -406,7 +406,7 @@ for (String mod : otherMods) { Optional omref = finder.find(mod); if (omref.isPresent()) { - ModuleReference mref = omref.get(); + ModuleReference mref = omref.getWhenPresent(); map.putIfAbsent(mod, mref); mrefs.add(mref); } else { --- old/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModuleDescriptorPlugin.java 2016-04-25 14:51:00.000000000 -0700 +++ new/src/jdk.jlink/share/classes/jdk/tools/jlink/internal/plugins/SystemModuleDescriptorPlugin.java 2016-04-25 14:51:00.000000000 -0700 @@ -485,11 +485,11 @@ } if (md.version().isPresent()) { - version(md.version().get()); + version(md.version().getWhenPresent()); } if (md.mainClass().isPresent()) { - mainClass(md.mainClass().get()); + mainClass(md.mainClass().getWhenPresent()); } putModuleDescriptor(); --- old/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java 2016-04-25 14:51:01.000000000 -0700 +++ new/src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java 2016-04-25 14:51:01.000000000 -0700 @@ -263,7 +263,7 @@ name); } - URI uri = omref.get().location().get(); + URI uri = omref.getWhenPresent().location().getWhenPresent(); modPaths.put(name, Paths.get(uri)); } @@ -346,21 +346,21 @@ Optional mc = md.mainClass(); if (mc.isPresent()) - sb.append("\n main-class " + mc.get()); + sb.append("\n main-class " + mc.getWhenPresent()); Optional osname = md.osName(); if (osname.isPresent()) - sb.append("\n operating-system-name " + osname.get()); + sb.append("\n operating-system-name " + osname.getWhenPresent()); Optional osarch = md.osArch(); if (osarch.isPresent()) - sb.append("\n operating-system-architecture " + osarch.get()); + sb.append("\n operating-system-architecture " + osarch.getWhenPresent()); Optional osversion = md.osVersion(); if (osversion.isPresent()) - sb.append("\n operating-system-version " + osversion.get()); + sb.append("\n operating-system-version " + osversion.getWhenPresent()); try { Method m = ModuleDescriptor.class.getDeclaredMethod("hashes"); @@ -370,7 +370,7 @@ (Optional) m.invoke(md); if (optHashes.isPresent()) { - Hasher.DependencyHashes hashes = optHashes.get(); + Hasher.DependencyHashes hashes = optHashes.getWhenPresent(); hashes.names().stream().forEach(mod -> sb.append("\n hashes ").append(mod).append(" ") .append(hashes.algorithm()).append(" ") @@ -580,7 +580,7 @@ + " dependencies, unable to find module " + dn + " on module path"); } - descriptors.add(omref.get().descriptor()); + descriptors.add(omref.getWhenPresent().descriptor()); } catch (FindException x) { throw new IOException("error reading module path", x); }