Files
openide/java/java-impl/resources/inspectionDescriptions/OptionalGetWithoutIsPresent.html
2025-02-05 04:43:28 +00:00

15 lines
525 B
HTML

<html>
<body>
Reports calls to <code>get()</code> on an <code>Optional</code> without checking that it has a value.
<p>Calling <code>Optional.get()</code> on an empty <code>Optional</code> instance will throw an exception.</p>
<p><b>Example:</b></p>
<pre><code>
<b>void</b> x(List&lt;Integer> list) {
<b>final</b> Optional&lt;Integer> optional =
list.stream().filter(x -> x > 10).findFirst();
<b>final</b> Integer result = optional.get(); // problem here
}
</code></pre>
<!-- tooltip end -->
</body>
</html>