[java] Inspection description updated

GitOrigin-RevId: f3fb16144a87469fa3e42c74e69c9600fff17347
This commit is contained in:
Andrey.Cherkasov
2021-03-18 10:49:50 +00:00
committed by intellij-monorepo-bot
parent cd52f351c0
commit 494abe4f2a
24 changed files with 264 additions and 137 deletions
@@ -1,16 +1,19 @@
<html>
<body>
Shows references to static methods and fields
via a class instance rather than a class itself.<br>
<br>
Example:<br>
<code>String s = String.valueOf(0); // correct: static method qualified with class name</code><br>
<code>String s1 = s.valueOf(0); // wrong: static method qualified with class instance</code><br>
<br>
While allowed by Java Language Specification,
referring to static members via instance variables makes the code confusing
as the reader may think that the result of the method depends on the instance.<br>
<br>
Quick fix: replaces the instance variable with the class name.
<p>Shows references to static methods and fields via a class instance rather than a class itself. While
allowed by Java Language Specification, referring to static members via instance variables makes the
code confusing as the reader may think that the result of the method depends on the instance.</p>
<p>Quick-fix replaces the instance variable with the class name.</p>
<p>Example:</p>
<pre>
String s1 = s.valueOf(0);
</pre>
<p>After the quick-fix is applied the result looks like:</p>
<pre>
String s = String.valueOf(0);
</pre>
<!-- tooltip end -->
<p>
</body>
</html>
@@ -1,15 +1,14 @@
<html>
<body>
The inspection checks that the arguments provided to Method.invoke() and Constructor.newInstance()
match the signature specified in Class.getMethod() and Class.getConstructor()
<!-- tooltip end -->
Checks that the arguments provided to <code>Method.invoke()</code> and <code>Constructor.newInstance()</code>
match the signature specified in <code>Class.getMethod()</code> and <code>Class.getConstructor()</code>
<p>Example:</p>
<pre><code>
<pre>
Method m = myObj.getClass().getMethod("myMethod", <b>int</b>.class);
<i>// the argument should be an <b>int</b> value</i>
m.invoke(myObj, "<b>abc</b>");
</code></pre>
</pre>
<!-- tooltip end -->
<p><small>New in 2017.2</small></p>
</body>
</html>
@@ -4,17 +4,23 @@ Reports cases where the minimum or the maximum of two numbers can be calculated
<code>Math.max()</code> or <code>Math.min()</code> instead of doing it manually.
<p>Example:</p>
<pre>
public int getMinWeight(int typeDiffWeight, int rawTypeDiffWeight) {
return (rawTypeDiffWeight &lt; typeDiffWeight ? rawTypeDiffWeight : typeDiffWeight);
public int min(int a, int b) {
return b &lt; a ? b : a;
}
</pre>
<p>Will be replaced with:</p>
<p>After the fix is applied, the result will be like this:</p>
<pre>
public int getMinWeight(int typeDiffWeight, int rawTypeDiffWeight) {
return Math.min(rawTypeDiffWeight, typeDiffWeight);
public int min(int a, int b) {
return Math.min(a, b);
}
</pre>
<!-- tooltip end -->
<p>
Use the checkbox below to disable this inspection for <code>double</code> and <code>float</code>
This might be useful because quick-fix may slightly break semantics for <code>float</code>/
<code>double</code> when handling <code>NaN</code>. Thought in most cases it will actually fix
the subtle bug when users did not care about <code>NaN</code>.
</p>
<p><small>New in 2019.2</small></p>
</body>
</html>
@@ -1,13 +1,25 @@
<html>
<body>
This inspection warns when <code>null</code> is assigned to <code>Optional</code> variable or returned from method returning
<code>Optional</code>. It's recommended to use <code>Optional.empty()</code> (or <code>Optional.absent()</code> for Guava) to denote
an empty value.
<p>
Use checkbox below to report also comparisons like <b>optional == null</b>. While in rare cases (e.g. lazily initialized optional field)
this might be correct, usually optional variable is never null, and probably <b>optional.isPresent()</b> was intended.
</p>
Reports <code>null</code> assigned to <code>Optional</code> variable or returned from method returning <code>Optional</code>.
It's recommended to use <code>Optional.empty()</code> (or <code>Optional.absent()</code> for Guava) to denote an empty value.
<p>Example:</p>
<pre>
Optional&lt;Integer&gt; foo(boolean flag) {
return flag ? Optional.of(42) : null;
}
</pre>
<p>After the fix is applied, the result will be like this:</p>
<pre>
Optional&lt;Integer&gt; foo(boolean flag) {
return flag ? Optional.of(42) : Optional.empty();
}
</pre>
<!-- tooltip end -->
<p>
Use the checkbox below to report also comparisons like <code>optional == null</code>. While in rare cases (e.g. lazily initialized
optional field) this might be correct, usually optional variable is never null, and probably <code>optional.isPresent()</code> was
intended.
</p>
<p>This inspection only reports if the language level of the project or module is 8 or higher</p>
<p><small>New in 2017.2</small>
</body>
@@ -1,23 +1,23 @@
<html>
<body>
Reports <code>Optional</code> call chains which could be replaced with a sequence of 'if' statements.
<!-- tooltip end -->
<p>Example:
<pre><code>
Reports <code>Optional</code> call chains which could be replaced with a sequence of <code>if</code> statements.
<p>Example:</p>
<pre>
return Optional.ofNullable(name)
.map(this::extractInitials)
.map(initials -> initials.toUpperCase(Locale.ENGLISH))
.orElseGet(this::getDefault);
</code></pre>
<p>can be replaced with</p>
<pre><code>
</pre>
<p>After the fix is applied, the result will be like this:</p>
<pre>
if (name != null) {
String initials = extractInitials(name);
if (initials != null) return initials.toUpperCase(Locale.ENGLISH);
}
return getDefault();
</code></pre>
<p>This inspection only reports if the configured language level is 8 or higher.</p>
</pre>
<!-- tooltip end -->
<p>This inspection only reports if the language level of the project or module is 8 or higher</p>
<p><small>New in 2020.2</small></p>
</body>
</html>
@@ -1,5 +1,20 @@
<html>
<body>
Reports redundant local variable types. Theses types can be inferred from the context and thus be replaced with <b>var</b>.
Reports redundant local variable types. Theses types can be inferred from the context and thus be replaced with <code>var</code>.
<p>Example:</p>
<pre>
void test(InputStream s) {
try (InputStream in = s) {}
}
</pre>
<p>After the fix is applied, the result will be like this:</p>
<pre>
void test(InputStream s) {
try (var in = s) {}
}
</pre>
<!-- tooltip end -->
<p>
</body>
</html>
@@ -1,7 +1,8 @@
<html>
<body>
Reports redundant constructors declared inside Java records. Examples:
<pre><code>
Reports redundant constructors declared inside Java records.
<p>Examples:</p>
<pre>
record Point(int x, int y) {
public Point {} // could be removed
}
@@ -21,7 +22,7 @@ Reports redundant constructors declared inside Java records. Examples:
this.to = to;
}
}
</code></pre>
</pre>
<!-- tooltip end -->
<p>This inspection only reports if the configured language level is 14 Preview or 15 Preview.</p>
<p><small>New in 2020.1</small></p>
@@ -1,13 +1,17 @@
<html>
<body>
Reports redundant calls to unmodifiable collection wrappers within the Collections class.
If the argument that is passed to an unmodifiable collection wrapper is already immutable, such wrapping becomes pointless.
Reports redundant calls to unmodifiable collection wrappers within the
Collections class. If the argument that is passed to an unmodifiable
collection wrapper is already immutable, such wrapping becomes pointless.
<p>Example:</p>
<pre>
<code>Collections.unmodifiableList(Collections.singletonList("abc"));
</code>
Collections.unmodifiableList(Collections.singletonList("abc"));
</pre>
In order to detect the methods that return unmodifiable collections, the inspection uses the <code>org.jetbrains.annotations.Unmodifiable</code> and <code>org.jetbrains.annotations.UnmodifiableView</code> annotations. Use them to extend the inspection to your own unmodifiable collection wrappers.
In order to detect the methods that return unmodifiable collections, the
inspection uses the <code>org.jetbrains.annotations.Unmodifiable</code>
and <code>org.jetbrains.annotations.UnmodifiableView</code> annotations.
Use them to extend the inspection to your own unmodifiable collection
wrappers.
<!-- tooltip end -->
<p><small>New in 2020.3</small></p>
</body>
@@ -1,20 +1,23 @@
<html>
<body>
This inspection suggests to replace null check with Objects/Stream static method.
<!-- tooltip end -->
Example:
<pre><code>
Suggests replacing null check with <code>Objects</code>/<code>Stream</code> static method.
<p>Example:</p>
<pre>
if (message == null) {
application.messageStorage().save(new EmptyMessage());
} else {
application.messageStorage().save(message);
}
</code></pre>
<p>can be replaced with</p>
<pre><code>
</pre>
<p>After the quick-fix is applied the result looks like:</p>
<pre>
application.messageStorage()
.save(Objects.requireNonNullElseGet(message, () -> new EmptyMessage()));
</code></pre>
</pre>
<!-- tooltip end -->
<p>
Use the checkbox below to not warn if length of replacement bigger than original.
</p>
<p><small>New in 2017.3</small></p>
</body>
</html>
@@ -1,7 +1,14 @@
<html>
<body>
This inspection finds all usages of methods that have <b><font color="#000080">@since</font></b> tag in
their documentation.<br><br>
This may be useful when development is performed under newer SDK version as the target platform for production.<br><br>
Reports usages of API which isn't available at the configured language level. API availability is defined
by the version specified in the <code>@since</code> tag in its documentation. This may be useful because
language level can differ from your project SDK and it is possible that there is no such API in JDK, on
which the code will be run.
<!-- tooltip end -->
<p>
Use the radio buttons below to forbid API usages respecting to project language level settings or custom
language level.
</p>
<p><small>New in 2018.2</small></p>
</body>
</html>
@@ -1,13 +1,29 @@
<html>
<body>
Warns when calling some method in a loop (e.g. <code>collection.add(x)</code>) could be replaced when calling a bulk method
(e.g. <code>collection.addAll(listOfX)</code>.
<p>
If checkbox "Use Arrays.asList() to wrap arrays" is checked, the inspection will warn even if the original code iterates over
an array while bulk method requires a <code>Collection</code>. In this case the quick-fix action will automatically
wrap an array with <code>Arrays.asList()</code> call.
</p>
Warns when calling some method in a loop (e.g. <code>collection.add(x)</code>) could be
replaced when calling a bulk method (e.g. <code>collection.addAll(listOfX)</code>.
<p>Example:</p>
<pre>
void test(Collection&lt;Integer&gt; numbers) {
List&lt;Integer&gt; result = new ArrayList<>();
for (Integer i : numbers) {
result.add(i);
}
}
</pre>
<p>After the fix is applied, the result will be like this:</p>
<pre>
void test(Collection&lt;Integer&gt; numbers) {
List&lt;Integer&gt; result = new ArrayList<>();
result.addAll(numbers);
}
</pre>
<!-- tooltip end -->
<p>
Use the checkbox below to warn even if the original code iterates over an array while
bulk method requires a <code>Collection</code>. In this case the quick-fix action will
automatically wrap an array with <code>Arrays.asList()</code> call.
</p>
<small>New in 2017.1</small>
</body>
</html>
@@ -1233,7 +1233,7 @@ inspection.empty.method.display.name=Empty method
inspection.unused.assignment.display.name=Unused assignment
inspection.unchecked.warning.display.name=Unchecked warning
inspection.convert.2.streamapi.display.name=Loop can be collapsed with Stream API
inspection.optional.to.if.display.name=Optional can be replaced with sequence of if statements
inspection.optional.to.if.display.name='Optional' can be replaced with sequence of 'if' statements
inspection.stream.to.loop.display.name=Stream API call chain can be replaced with loop
inspection.anonymous.2.method.ref.display.name=Anonymous type can be replaced with method reference
inspection.convert.2.method.ref.display.name=Lambda can be replaced with method reference
@@ -493,7 +493,7 @@ readresolve.writereplace.protected.problem.descriptor=<code>#ref()</code> not de
missing.serial.annotation.display.name=@Serial annotation could be used
missing.serial.annotation.on.field.problem.descriptor=<code>#ref</code> can be annotated with @Serial annotation
missing.serial.annotation.on.method.problem.descriptor=<code>#ref()</code> can be annotated with @Serial annotation
serial.annotation.used.on.wrong.member.display.name=@Serial annotation used on wrong member
serial.annotation.used.on.wrong.member.display.name='@Serial' annotation used on wrong member
serial.annotation.used.on.wrong.member.problem.descriptor=Annotated member is not a part of the serialization mechanism
serializable.record.contains.ignored.members.display.name='record' contains ignored members
serializable.record.contains.ignored.field.problem.descriptor=<code>#ref</code> will be ignored during record serialization
@@ -2127,7 +2127,7 @@ try.statement.with.multiple.resources.name='try' statement with multiple resourc
try.statement.with.multiple.resources.quickfix=Split 'try' statement with multiple resources
multi.catch.can.be.split.name=Multi-catch can be split into separate catch blocks
multi.catch.can.be.split.quickfix=Split multi-catch into separate 'catch' blocks
assertion.can.be.if.name=Assertion can be replaced with if statement
assertion.can.be.if.name=Assertion can be replaced with 'if' statement
assert.can.be.if.quickfix=Replace 'assert' with 'if' statement
if.can.be.assertion.name=Statement can be replaced with 'assert' or 'Objects.requireNonNull'
if.can.be.assertion.replace.with.assertion.quickfix=Replace statement with 'assert' statement
@@ -2259,7 +2259,7 @@ inspection.constant.expression.fix.family.name=Compute constant value
inspection.redundant.compare.call.display.name=Redundant 'compare()' method call
inspection.redundant.compare.call.fix.name=Inline 'compare()' call
inspection.simplifiable.if.statement.display.name=If statement can be replaced with ?:, \\&\\&, ||, ==, or != expression
inspection.simplifiable.if.statement.display.name='if' statement can be replaced with conditional or boolean expression
inspection.simplifiable.if.statement.message=If statement can be replaced with ''{0}''
inspection.simplifiable.if.statement.option.dont.warn.on.ternary=Don't suggest '?:' operator
inspection.simplifiable.if.statement.fix.name=Replace ''if else'' with ''{0}''
@@ -1,11 +1,17 @@
<html>
<body>
Reports <b>assert</b> statements.
For example, <br>
<code><b>assert</b> param != <b>null</b>;</code>
<p>Quick fix replaces it with
<b>if</b> statement throwing an <b>java.lang.AssertionError</b>.
<p>Example:<br>
<code>if (param == <b>null</b>) <b>throw new</b> AssertionError();</code>
Reports <code>assert</code> statements and suggests replacing them with
<code>if</code> statement throwing an <code>java.lang.AssertionError</code>.
<p>Example:</p>
<pre>
assert param != null;
</pre>
<p>After the quick-fix is applied the result looks like:</p>
<pre>
if (param == null) throw new AssertionError();
</pre>
<!-- tooltip end -->
<p>
</body>
</html>
</html>
@@ -1,10 +1,22 @@
<html>
<body>
Reports calls to <b>equals()</b> or <b>compareTo()</b> were an object is compared for equality with itself.
This means the argument and the qualifier to the call are identical, and it will always return <b>true</b> for <b>equals()</b>
or always <b>0</b> for <b>compareTo()</b>.
Also reports call to static methods <b>Objects.equals()</b>, <b>Objects.deepEquals()</b>, <b>Arrays.equals()</b>, <b>Comparator.compare</b>
and similar methods with two identical arguments.
Reports calls to <code>equals()</code> or <code>compareTo()</code> were an object is compared for equality
with itself. This means the argument and the qualifier to the call are identical, and it will always return
<code>true</code> for <code>equals()</code> or always <code>0</code> for <code>compareTo()</code>. Also
reports call to static methods <code>Objects.equals()</code>, <code>Objects.deepEquals()</code>,
<code>Arrays.equals()</code>, <code>Comparator.compare</code> and similar methods with two identical arguments.
<p>Example:</p>
<pre>
class Foo {
boolean foo(Object o) {
return o.equals(o); // bad
}
boolean bar(String[] ss) {
return Arrays.equals(ss, ss); // bad
}
}
</pre>
<!-- tooltip end -->
<p>
</body>
@@ -1,8 +1,10 @@
<html>
<body>
Reports a <b>Externalizable</b> classes without a public no-argument constructor.
When an Externalizable object is reconstructed, an instance is created using the public no-arg constructor before the readExternal
method called. If a public no-arg constructor is not present a <b>java.io.InvalidClassException</b> will be thrown at runtime.
Reports a <code>Externalizable</code> classes without a public no-argument constructor.
When an Externalizable object is reconstructed, an instance is created using the public
no-arg constructor before the <code>readExternal</code> method called. If a public
no-arg constructor is not present a <code>java.io.InvalidClassException</code> will be
thrown at runtime.
<!-- tooltip end -->
<p>
</body>
@@ -1,6 +1,16 @@
<html>
<body>
Reports sealed classes whose permits clause doesn’t contain some of the subclasses from the same file.
Reports sealed classes whose permits clause doesn't contain some of the subclasses from the same file.
<p>Example:</p>
<pre>
sealed class A {}
final class B extends A {}
</pre>
<p>After the fix is applied, the result will be like this:</p>
<pre>
sealed class A permits B {}
final class B extends A {}
</pre>
<!-- tooltip end -->
<p><small>New in 2020.3</small></p>
</body>
@@ -1,10 +0,0 @@
<html>
<body>
Reports classes annotated with @RunWith(JUnitPlatform.class) which provide no test methods. These classes won't start tests because
org.junit.vintage.engine.discovery.DefensiveAllDefaultPossibilitiesBuilder.DefensiveAnnotatedBuilder prevents recursion and
org.junit.vintage.engine.discovery.DefensiveAllDefaultPossibilitiesBuilder.DefensiveJUnit4Builder expects test methods
<!-- tooltip end -->
<p>
<small>New in 2017.2</small>
</body>
</html>
@@ -1,7 +1,15 @@
<html>
<body>
Reports String literals of length one being used in concatenation.
These literals may be replaced by equivalent character literals, gaining some performance enhancement.
Reports string literals of length one being used in concatenation. These literals
may be replaced by equivalent character literals, gaining some performance enhancement.
<p>Example:</p>
<pre>
String hello = hell + "o";
</pre>
<p>After the quick-fix is applied the result looks like:</p>
<pre>
String hello = hell + 'o';
</pre>
<!-- tooltip end -->
<p>
@@ -1,9 +1,21 @@
<html>
<body>
Reports cases when <b>==</b> or <b>!=</b> is applied to a newly allocated object
instead of an <b>equals()</b> call. Newly allocated objects cannot be equal to other objects,
thus the compared objects are always unequal. The inspection also may detect
newly created objects returned from simple methods.
Reports cases when <code>==</code> or <code>!=</code> is applied to a newly allocated object
instead of an <code>equals()</code> call. Newly allocated objects cannot be equal to other
objects, thus the compared objects are always unequal. The inspection also may detect newly
created objects returned from simple methods.
<p>Example:</p>
<pre>
void test(Object obj) {
if (new Object() == obj) {...}
}
</pre>
<p>After the fix is applied, the result will be like this:</p>
<pre>
void test(Object obj) {
if (new Object().equals(obj)) {...}
}
</pre>
<!-- tooltip end -->
<p>
<small>New in 2018.3</small>
@@ -1,26 +1,26 @@
<html>
<body>
Reports methods and fields in <b>Serializable</b> and <b>Externalizable</b> classes that are not suitable to be annotated with the <b>java.io.Serial</b> annotation.
<p>
Examples:<br>
<code><pre>
Reports methods and fields in <code>Serializable</code> and <code>Externalizable</code>
classes that are not suitable to be annotated with the <code>java.io.Serial</code> annotation.
<p>Examples:</p>
<pre>
class Test implements Serializable {
@Serial //The annotated field is not a part of serialization mechanism as it's not final
@Serial // The annotated field is not a part of serialization mechanism as it's not final
private static long serialVersionUID = 7874493593505141603L;
@Serial //The annotated method is not a part of the serialization mechanism as it's not private
@Serial // The annotated method is not a part of the serialization mechanism as it's not private
void writeObject(ObjectOutputStream out) throws IOException {
}
}
</pre></code>
<code><pre>
</pre>
<pre>
class Test implements Externalizable {
@Serial //The annotated method is not a part of the serialization mechanism as it's inside Externalizable class
@Serial // The annotated method is not a part of the serialization mechanism as it's inside Externalizable class
private void writeObject(ObjectOutputStream out) throws IOException {
}
}
</pre></code>
<p>To get more information about all valid cases, refer the documentation for <b>java.io.Serial</b>.</p>
</pre>
<p>To get more information about all valid cases, refer the documentation for <code>java.io.Serial</code>.</p>
<!-- tooltip end -->
<p>This inspection only reports if the language level of the project or module is 14 or higher.</p>
<p><small>New in 2020.3</small></p>
@@ -1,19 +1,26 @@
<html>
<body>
Reports 'if' statements which can be replaced with condition using '&&', '||' or '?:' operator.
The result is usually shorter, but not always more clear, so it's not advised to apply it everywhere.
Also this change may reduce compiled bytecode size which could be useful in some environments like Java ME.
Reports <code>if</code> statements that can be replaced with condition using <code>&&</code>, <code>||</code>,
<code>==</code>, <code>!=</code> or <code>?:</code> operator. The result is usually shorter, but not always more
clear, so it's not advised to apply it everywhere. Also this change may reduce compiled bytecode size which could
be useful in some environments like Java ME.
<p>Example:</p>
<pre>
if (condition) return true; else return foo;
</pre>
<p>After the fix is applied, the result will be like this:</p>
<pre>
return condition || foo;
</pre>
<!-- tooltip end -->
<p>
Example: <b>if (<i>condition</i>) return true; else return <i>foo</i>;</b> could be replaced with
<b>return <i>condition</i> || <i>foo</i>;</b>
</p>
<!-- tooltip end -->
<p>
Use the first checkbox to skip warning when '?:' operator is suggested. In this case only '&&' and '||' suggestions
will be highlighted. The fix action to replace with '?:' will still be available in the editor.
Use the first checkbox below to skip warning when <code>?:</code> operator is suggested. In this case only
<code>&&</code>, <code>||</code>, <code>==</code> and <code>!=</code> suggestions will be highlighted. The
fix action to replace with <code>?:</code>will still be available in the editor.
</p>
<p>
Use the second checkbox to skip warning on 'if-else' chains. The fix action will still be available in the editor.
Use the second checkbox below to skip warning on <code>if-else</code> chains. The fix action will still be
available in the editor.
</p>
<p><small>New in 2018.2</small></p>
</body>
@@ -1,8 +1,23 @@
<html>
<body>
Reports <b>try finally</b> statements which can use Java 7
Automatic Resource Management. A quickfix is available to convert the <b>try finally</b>
statement into a <b>try</b> with resources statement.
Reports <code>try</code>-<code>finally</code> statements which can use Java 7 Automatic Resource
Management. A quick-fix is available to convert the <code>try</code>-<code>finally</code> statement
into a <code>try</code>-with-resources statement.
<p>Example:</p>
<pre>
PrintStream printStream = new PrintStream(fileName);
try {
printStream.print(true);
} finally {
printStream.close();
}
</pre>
<p>A quick-fix is provided to pass the cause to constructor:</p>
<pre>
try (PrintStream printStream = new PrintStream(fileName)) {
printStream.print(true);
}
</pre>
<!-- tooltip end -->
<p>This inspection only reports if the language level of the project or module is 7 or higher</p>
</body>
@@ -2,15 +2,14 @@
<body>
Reports unnecessary creation of temporary objects when converting
from Strings to primitive types.
<p>
For example:
<code><pre>
new Integer("3").intValue()
</pre></code>
will be reported, and can be automatically converted to:
<code><pre>
Integer.valueOf("3")
</pre></code>
<p>Example:</p>
<pre>
new Integer("3").intValue()
</pre>
<p>After the quick-fix is applied the result looks like:</p>
<pre>
Integer.valueOf("3")
</pre>
<!-- tooltip end -->
<p>