Files
openide/java/java-impl/resources/inspectionDescriptions/IfCanBeAssertion.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

24 lines
953 B
HTML

<html>
<body>
Reports <code>if</code> statements that throw only <code>java.lang.Throwable</code> from a <code>then</code> branch
and do not have an <code>else</code> branch. Such statements can be converted to more compact <code>assert</code> statements.
<p>
The inspection also reports Guava's <code>Preconditions.checkNotNull()</code>.
They can be replaced with a <code>Objects.requireNonNull()</code> call for which a library may not be needed.</p>
<p>Example:</p>
<pre><code>
<b>if</b> (x == 2) <b>throw new</b> RuntimeException("fail");
<b>if</b> (y == null) <b>throw new</b> AssertionError();
Preconditions.checkNotNull(z, "z");
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
<b>assert</b> x != 2 : "fail";
Objects.requireNonNull(y);
Objects.requireNonNull(z, "z");
</code></pre>
<!-- tooltip end -->
<p>By default, this inspection provides a quick-fix in the editor without code highlighting.</p>
</body>
</html>