mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java inspection descriptions updated
GitOrigin-RevId: 591f647d7365c5c467ad9c400eba2d1afcb2a84c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
cb94c8c533
commit
997e1adc68
@@ -1,19 +1,19 @@
|
||||
<html>
|
||||
<body>
|
||||
Detects conditional breaks at the beginning or end of a loop and suggests to use a loop condition instead.
|
||||
Reports conditional breaks at the beginning or end of a loop and suggests to use a loop condition instead, to create shorter code.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
<b>while</b> (true) {
|
||||
<b>if</b> (i == 23) <b>break</b>;
|
||||
i++;
|
||||
}
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
<b>while</b> (i != 23) {
|
||||
i++;
|
||||
}
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
Example:
|
||||
<p><code>
|
||||
while(true) {
|
||||
if(i == 23) break;
|
||||
i++;
|
||||
}
|
||||
</code></p>
|
||||
<p>Will be replaced with:
|
||||
<p><code>
|
||||
while(i != 23) {
|
||||
i++;
|
||||
}
|
||||
</code></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,8 +1,18 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports various method contract (@Contract annotation) well-formedness issues:
|
||||
Reports issues in method <code>@Contract</code> annotations. The types of issues that can be reported are:
|
||||
<ul>
|
||||
<li>Errors in contract syntax</li>
|
||||
<li>Contracts not conforming to the method signature (wrong parameter count)</li>
|
||||
<li>Method implementations that contradict the contract (e.g. returning "true" when the contract says "false")</li>
|
||||
<li>Method implementations that contradict the contract (e.g. returning <code>true</code> when the contract says <code>false</code>)</li>
|
||||
</ul>
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
// method has no parameters, but contract expects 1
|
||||
@Contract("_ -> fail")
|
||||
<b>void</b> x() {
|
||||
<b>throw</b> new AssertionError();
|
||||
}
|
||||
</code></pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,25 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports loops which can be replaced with stream API calls.
|
||||
<p>
|
||||
The Stream API is not available under Java 7 or earlier JVMs.
|
||||
Reports loops which can be replaced with stream API calls using lambda expressions.
|
||||
This inspection only reports if the configured language level is 8 or higher.
|
||||
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
<b>boolean</b> check(List<String> data) {
|
||||
<b>for</b> (String e : data) {
|
||||
String trimmed = e.trim();
|
||||
<b>if</b> (!trimmed.startsWith("xyz")) {
|
||||
<b>return</b> false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
<b>boolean</b> check(List<String> data) {
|
||||
<b>return</b> data.stream().map(String::trim).allMatch(trimmed -> trimmed.startsWith("xyz"));
|
||||
}
|
||||
</code></pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,8 +1,24 @@
|
||||
<html>
|
||||
<body>
|
||||
The inspection finds commonly used class/interface that could be extended/implemented instead of extending too broad interface or class.
|
||||
Reports when a more specific commonly used class or interface could be extended or implemented, instead of the current one.
|
||||
The super class needs to be located inside the project source files and
|
||||
the project needs to use the IntelliJ IDEA build system for this inspection to work.
|
||||
By default this inspection does not highlight in the editor, but only provides a quick fix.
|
||||
<p>Example:
|
||||
<pre>
|
||||
class MyInheritor implements A {} // B suggested on the A reference
|
||||
|
||||
interface A {}
|
||||
|
||||
abstract class B implements A {}
|
||||
|
||||
abstract class C1 extends B {}
|
||||
abstract class C2 extends B {}
|
||||
abstract class C3 extends B {}
|
||||
abstract class C4 extends B {}
|
||||
abstract class C5 extends B {}
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
The inspection works only if a project is built using IntelliJ IDEA build system and a super class is located inside project source files.
|
||||
<p><small>New in 2017.2</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,18 +1,39 @@
|
||||
<html>
|
||||
<body>
|
||||
This inspection helps to convert unmodifiable collections created before Java 9 to new collection factory methods
|
||||
like <code>List.of</code> or <code>Set.of</code>. Also since Java 10 the conversion to <code>List.copyOf</code>, etc. could be suggested.
|
||||
Reports <code>java.util.Collections</code> unmodifiable collection calls,
|
||||
that can be converted to newer collection factory methods.
|
||||
These can be replaced with e.g. <code>List.of()</code> or <code>Set.of()</code> introduced in Java 9,
|
||||
or <code>List.copyOf()</code> introduced in Java 10.
|
||||
|
||||
<p>Not that, in contrast to <code>java.util.Collections</code> methods, the Java 9 collection factory methods
|
||||
<ul>
|
||||
<li>do not accept <code>null</code> values
|
||||
<li>require unique set elements and map keys
|
||||
<li>do not accept <code>null</code> arguments to query methods like <code>List.contains()</code> or <code>Map.get()</code> of the collections returned.
|
||||
</ul>
|
||||
When these cases are violated, exceptions are thrown.
|
||||
This can change the semantics of the code after migration.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
List<Integer> even = Collections.unmodifiableList(
|
||||
Arrays.asList(2, 4, 6, 8, 10, 2));
|
||||
List<Integer> evenCopy = Collections.unmodifiableList(
|
||||
new ArrayList<>(list1));
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
List<Integer> even = List.of(2, 4, 6, 8, 10, 2);
|
||||
List<Integer> evenCopy = List.copyOf(list);
|
||||
</code></pre>
|
||||
<p>This inspection only reports if the configured language level is 9 or higher.
|
||||
|
||||
<!-- tooltip end -->
|
||||
<p>Note that Java 9 collection factory methods do not accept null values. Also, set elements and map keys are required to be different.
|
||||
It's not always possible to statically check whether original elements are different and not null. Using the checkbox you may enforce
|
||||
the inspection to warn only if original elements are compile-time constants.</p>
|
||||
<p>
|
||||
Also it should be noted that some query methods like <code>Collection.contains()</code> or <code>Map.get</code>
|
||||
don't tolerate nulls as well. E.g., <code>Collection.contains()</code>
|
||||
throws a NullPointerException instead of returning false.
|
||||
Thus, even if the collection is initialized with non-null values only, the semantics of the code may change after migration.
|
||||
</p>
|
||||
<p>This inspection is available since Java 9 only.</p>
|
||||
<small>New in 2017.2</small>
|
||||
Use the first checkbox below to only report if the supplied arguments are compile-time constants.
|
||||
This reduces the chance of changes in behaviour,
|
||||
because it's not always possible to statically check whether original elements are unique and not <code>null</code>.
|
||||
<p>
|
||||
Use the second checkbox to suggest a <code>Map.ofEntries()</code> replacement for unmodifiable maps with more than 10 entries.
|
||||
<p><small>New in 2017.2</small>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,15 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports <b>Optional.get()</b> method calls without an earlier check that the optional has a value.
|
||||
If the optional is empty, calling <b>Optional.get()</b> will throw an exception.
|
||||
Reports <code>Optional.get()</code> method calls without an earlier check that the optional has a value.
|
||||
If the optional is empty, calling <code>Optional.get()</code> will throw an exception.
|
||||
<!-- tooltip end -->
|
||||
<p>Example:
|
||||
<pre>
|
||||
<b>void</b> x(List<Integer> list) {
|
||||
<b>final</b> Optional<Integer> optional =
|
||||
list.stream().filter(x -> x > 10).findFirst();
|
||||
<b>final</b> Integer result = optional.get(); // problem here
|
||||
}
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,7 +1,19 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports code fragments that could be replaced via the <b>Files.readString</b> and <b>Files.writeString</b>
|
||||
methods introduced in Java 11.
|
||||
Reports code fragments that read or write a String as bytes using <code>java.nio.file.Files</code>.
|
||||
These can be replaced with calls to the <code>Files.readString()</code> and <code>Files.writeString()</code> methods, introduced in Java 11.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
String s = "example";
|
||||
Files.write(Paths.get("out.txt"), s.getBytes(StandardCharsets.UTF_8), StandardOpenOption.WRITE);
|
||||
s = new String(Files.readAllBytes(Paths.get("in.txt")), StandardCharsets.ISO_8859_1);
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
String s = "example";
|
||||
Files.writeString(Paths.get("out.txt"), s, StandardOpenOption.WRITE);
|
||||
s = Files.readString(Paths.get("in.txt"), StandardCharsets.ISO_8859_1);
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2018.3</small></p>
|
||||
</body>
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
<html>
|
||||
<body>
|
||||
The implementation of the <code>'java.util.AbstractSet#removeAll'</code> method determines which is the smaller of this set and the
|
||||
specified collection, by invoking the size method on each. If this set has fewer elements, then the implementation iterates over
|
||||
this set, checking each element returned by the iterator in turn to see if it is contained in the specified collection. If it is
|
||||
so contained, it is removed from this set with the iterator's remove method. If the specified collection has fewer elements, then
|
||||
the implementation iterates over the specified collection, removing from this set each element returned by the iterator, using this
|
||||
set's remove method.
|
||||
|
||||
<p>It means that if the collection to remove is of equal or larger size than the set, then the implementation of the
|
||||
<code>'java.util.List#contains'</code> method is called, which in many implementations they will perform costly linear
|
||||
searches.
|
||||
</p>
|
||||
Reports calls to <code>java.util.Set.removeAll()</code> with a <code>java.util.List</code> argument.
|
||||
Such a call can be slow when the size of the argument is greater or equal than the size of the set,
|
||||
and the set is a subclass of <code>java.util.AbstractSet</code>.
|
||||
In this case <code>List.contains()</code> is called for every element in the set, which will perform a linear search.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
<b>public void</b> check(String... ss) {
|
||||
// possible O(n^2) complexity
|
||||
mySet.removeAll(List.of(ss));
|
||||
}
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
<b>public void</b> check(String... ss) {
|
||||
// O(n) complexity
|
||||
List.of(ss).forEach(mySet::remove);
|
||||
}
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2020.3</small></p>
|
||||
</body>
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports assignments and function calls where the name of the variable to which
|
||||
a value is assigned or the function parameter does not seem to match the name of the value assigned to it.
|
||||
For example:
|
||||
<pre><code><font color="#000080">
|
||||
Reports assignments and function calls where the name of the target variable or the function parameter does not match the name of the value assigned to it.
|
||||
<p>Example:
|
||||
<pre>
|
||||
<b>int</b> x = 0;
|
||||
<b>int</b> y = x;</font></code></pre> or <pre><code><font color="#000080">
|
||||
<b>int</b> y = x;
|
||||
</pre>
|
||||
or
|
||||
<pre><code>
|
||||
<b>int</b> x = 0, y = 0;
|
||||
Rectangle rc = <b>new</b> Rectangle(y, x, 20, 20);</font></code></pre>
|
||||
The configuration pane allows to specify the names which should not be used together: the error is reported
|
||||
Rectangle rc = <b>new</b> Rectangle(y, x, 20, 20);
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>The first panel below allows to specify the names which should not be used together: an error is reported
|
||||
if the parameter name or assignment target name contains words from one group and the name of the assigned or passed
|
||||
variable contains words from a different group.
|
||||
<p>The second panel below allows to specify methods that should not be checked but do have a potentially suspicious name.
|
||||
For example the <code>Integer.compare()</code> parameters are named <code>x</code> and <code>y</code>, but are unrelated to coordinates.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,6 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
Suggests to replace text block with a regular string literal.
|
||||
Suggests to replace text blocks with regular string literals.
|
||||
This could be part of an effort to migrate the code back to an earlier version of Java than 15.
|
||||
<!-- tooltip end -->
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
@@ -12,7 +13,7 @@ Suggests to replace text block with a regular string literal.
|
||||
hello();
|
||||
""");
|
||||
</code></pre>
|
||||
<p>can be replaced with</p>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
Object obj = engine.eval("function hello() {\n" +
|
||||
" print('\"Hello, world\"');\n" +
|
||||
|
||||
+1
-3
@@ -1,7 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
Lists modules which contain redundant dependencies on other modules.
|
||||
These dependencies can be safely removed.
|
||||
|
||||
Reports dependencies from one module to another, which are not used and can be safely removed.
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+11
-16
@@ -1,20 +1,15 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports calls to assertion methods with “expected” and “actual” arguments of incompatible types. Such calls often indicate that there is a bug.<br>
|
||||
The inspection applies to the following methods:<br>
|
||||
<ul>
|
||||
<li><b>org.junit.Assert.assertEquals(), org.junit.Assert.assertNotEquals()</b></li>
|
||||
<li><b>org.junit.Assert.assertSame(), org.junit.Assert.assertNotSame()</b></li>
|
||||
<li><b>org.assertj.core.api.Assert.isEqualTo(), org.assertj.core.api.Assert.isNotEqualTo()</b></li>
|
||||
<li><b>org.assertj.core.api.Assert.isSameAs(), org.assertj.core.api.Assert.isNotSameAs()</b></li>
|
||||
</ul>
|
||||
The <b>assertNotEquals()</b> and <b>isNotEqualTo()</b> methods are also reported,<br>
|
||||
however they are highlighted with a weak warning to take into account the case when the equals() contract is tested.
|
||||
<br><br>
|
||||
Test samples where <b>the warning is fired:</b><br>
|
||||
<code>assertEquals("1", 1);</code><br>
|
||||
<code>assertNotSame(new int[0], 0);</code><br>
|
||||
<code>// weak warning, because of a possible false positive case</code><br>
|
||||
<code>assertThat(foo).as("user type").isNotEqualTo(bar);</code><br>
|
||||
Reports calls to assertion methods where the “expected” and “actual” arguments are of incompatible types.
|
||||
Such calls often indicate that there is a bug in the test.
|
||||
This inspection checks the relevant JUnit, TestNG as well as AssertJ methods.
|
||||
<p>Examples:
|
||||
<pre>
|
||||
assertEquals("1", 1);
|
||||
assertNotSame(new int[0], 0);
|
||||
|
||||
// weak warning, may just test the equals() contract
|
||||
assertThat(foo).as("user type").isNotEqualTo(bar);
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
+19
-9
@@ -1,19 +1,29 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports any attempt to instantiate a new <b>Long</b>,
|
||||
<b>Integer</b>, <b>Short</b> or
|
||||
<b>Byte</b> object from a primitive <b>long</b>,
|
||||
<b>integer</b>, <b>short</b> or
|
||||
<b>byte</b>
|
||||
argument. It may be more efficient to use the static method <b>valueOf()</b>
|
||||
here (introduced in Java 5), which will cache objects for values between -128 and
|
||||
Reports any attempt to instantiate a new <code>Long</code>,
|
||||
<code>Integer</code>, <code>Short</code> or
|
||||
<code>Byte</code> object from a primitive <code>long</code>,
|
||||
<code>integer</code>, <code>short</code> or
|
||||
<code>byte</code>
|
||||
argument. It may be more efficient to use the static method <code>valueOf()</code>
|
||||
here (introduced in Java 5), which by default will cache objects for values between -128 and
|
||||
127 inclusive.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
Integer i = new Integer(1);
|
||||
Long l = new Long(1L);
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
Integer i = Integer.valueOf(1);
|
||||
Long l = Long.valueOf(1L);
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>This inspection only reports if the language level of the project or module is 5 or higher</p>
|
||||
<p>
|
||||
Use the first checkbox below to ignore calls to number constructors with a <b>String</b> argument.
|
||||
Use the first checkbox below to ignore calls to number constructors with a <code>String</code> argument.
|
||||
<p>
|
||||
Use the second checkbox to only report calls to deprecated constructors.
|
||||
<b>Long</b>, <b>Integer</b>, <b>Short</b> and<b>Byte</b> constructors are deprecated since JDK 9.
|
||||
<code>Long</code>, <code>Integer</code>, <code>Short</code> and<code>Byte</code> constructors are deprecated since JDK 9.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,14 +1,21 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports <b>if</b> statements (with no <b>else</b> branch) throwing <code>java.lang.Throwable</code>.
|
||||
Reports <code>if</code> statements which only throw a <code>java.lang.Throwable</code> from the then branch,
|
||||
and don't have an <code>else</code> branch.
|
||||
Also reports Guava's <code>Preconditions.checkNotNull()</code>.
|
||||
These can be replaced with an <code>assert</code> statement, or <code>Objects.requireNonNull()</code> call.
|
||||
<p>Example:
|
||||
<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 the result looks like:<br>
|
||||
<pre><code>
|
||||
<b>assert</b> x != 2 : "fail";
|
||||
Objects.requireNonNull(y);
|
||||
Objects.requireNonNull(z, "z");
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<br>For example:<br>
|
||||
<code><b>if</b> (param == 2) <b>throw new</b> Exception();</code>
|
||||
<br>or guava's:<br>
|
||||
<code>Preconditions.checkNotNull(param, message)</code>
|
||||
|
||||
<p>Quick fix replaces it with an <b>assert</b> statement.<br>
|
||||
Example:<br>
|
||||
<code><b>assert</b> param != 2;</code>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,12 +1,34 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports any inner classes which may safely be made <b>static</b>.
|
||||
An inner class may be <b>static</b> if it doesn't reference its enclosing instance.
|
||||
Reports any inner classes which may safely be made <code>static</code>.
|
||||
An inner class may be <code>static</code> if it doesn't reference its enclosing instance.
|
||||
<p>
|
||||
A <b>static</b> inner class does not keep an implicit reference to its enclosing instance.
|
||||
A <code>static</code> inner class does not keep an implicit reference to its enclosing instance.
|
||||
This prevents a common cause of memory leaks and uses less memory per instance of the class.
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
<b>public class</b> Outer {
|
||||
<b>class</b> Inner { // not static
|
||||
<b>public void</b> foo() {
|
||||
bar("x");
|
||||
}
|
||||
|
||||
<b>private void</b> bar(String string) {}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
<b>public class</b> Outer {
|
||||
<b>static class</b> Inner {
|
||||
<b>public void</b> foo() {
|
||||
bar("x");
|
||||
}
|
||||
|
||||
<b>private void</b> bar(String string) {}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,13 +1,21 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports any calls to <b>Math.random()</b> which are immediately
|
||||
cast to <b>int</b>. Casting a <b>double</b> between <b>0.0</b> (inclusive) and
|
||||
<b>1.0</b> (exclusive) will always round down to zero. A <b>Math.random()</b> value
|
||||
should first be multiplied with some factor before casting it to an <b>int</b> to
|
||||
Reports any calls to <code>Math.random()</code> which are immediately
|
||||
cast to <code>int</code>. Casting a <code>double</code> between <code>0.0</code> (inclusive) and
|
||||
<code>1.0</code> (exclusive) will always round down to zero. A <code>Math.random()</code> value
|
||||
should first be multiplied with some factor before casting it to an <code>int</code> to
|
||||
get a value between zero (inclusive) and the multiplication factor (exclusive).
|
||||
Another possible solution would be to use the <b>nextInt()</b> method of
|
||||
<b>java.util.Random</b>.
|
||||
<!-- tooltip end -->
|
||||
Another possible solution would be to use the <code>nextInt()</code> method of
|
||||
<code>java.util.Random</code>.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
<b>int</b> r = (<b>int</b>)Math.random() * 10;
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
<b>int</b> r = (<b>int</b>)(Math.random() * 10);
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+12
-4
@@ -1,8 +1,16 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports method references, like <code>MyClass::myMethod</code> and <code>myObject::myMethod</code>.
|
||||
<p> The quick fix for the inspection replaces the method reference with an equivalent lambda expression that invokes the method.
|
||||
<p>For example, the method reference <code>System.out::println</code> is replaced with
|
||||
<code>s -> System.out.println(s)</code>
|
||||
Reports method references, like <code>MyClass::myMethod</code> and <code>myObject::myMethod</code>,
|
||||
to allow them to be replaced with an equivalent lambda expression.
|
||||
Lambda expressions can be easier to modify than method references.
|
||||
By default this inspection does not highlight in the editor, but only provides a quick fix.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
System.out::println
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
s -> System.out.println(s)
|
||||
</code></pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,13 +1,25 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports any use of <b>==</b> or <b>!=</b>to test for Object equality, rather than the <b>equals()</b> method.
|
||||
Comparisons to <b>null</b> are not reported.
|
||||
Comparison of arrays, Strings or Numbers using <b>==</b> are also not reported, there are separate inspections for these three problems.
|
||||
Reports any use of <code>==</code> or <code>!=</code>to test for Object equality, rather than the <code>equals()</code> method.
|
||||
Comparisons to <code>null</code> are not reported.
|
||||
Comparison of arrays, Strings or Numbers using <b>==</b> are reported by separate inspections.
|
||||
Comparing objects using <code>==</code> or <code>!=</code> is usually a bug, because it compares objects by identity instead of equality.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
<b>if</b> (list1 == list2) {
|
||||
<b>return</b>;
|
||||
}
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
<b>if</b> (Object.equals(list1, list2)) {
|
||||
<b>return</b>;
|
||||
}
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
Use the checkboxes below to indicate whether uses of <b>==</b> between objects of
|
||||
an enumerated type, final class types without equals implementation or types with private constructors should be reported by this inspection.
|
||||
<p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
+15
-5
@@ -1,11 +1,21 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports pointless or pointlessly
|
||||
complicated boolean expressions. Such expressions include <b>and</b>ing with <b>true</b>,
|
||||
<b>or</b>ing with <b>false</b>,
|
||||
equality comparison with a boolean literal, or negation of a boolean literal. Such expressions may be the result of automated refactorings
|
||||
not completely followed through to completion, and in any case are unlikely to be what the developer
|
||||
intended to do.
|
||||
complicated boolean expressions. Such expressions include <code>&&</code>-ing with <code>true</code>,
|
||||
<code>||</code>-ing with <code>false</code>,
|
||||
equality comparison with a boolean literal, or negation of a boolean literal. Such expressions can be simplified.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
<b>boolean</b> a = !(x && <b>false</b>);
|
||||
<b>boolean</b> b = <b>false</b> || x;
|
||||
<b>boolean</b> c = x != <b>true</b>;
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
<b>boolean</b> a = <b>true</b>;
|
||||
<b>boolean</b> b = x;
|
||||
<b>boolean</b> c = !x;
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
Use the checkbox below to ignore named constants when determining if an expression is pointless.
|
||||
|
||||
+13
-12
@@ -1,22 +1,23 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports the implementations of <code>InvocationHandler.invoke</code> that do not proxy standard
|
||||
Reports the implementations of <code>InvocationHandler</code> that do not proxy standard
|
||||
<code>Object</code> methods like <code>hashCode()</code>, <code>equals()</code>, and <code>toString()</code>.
|
||||
Failing to handle these methods might cause unexpected problems upon calling them on a proxy instance.
|
||||
<p>
|
||||
Example:
|
||||
</p>
|
||||
<p>Example:
|
||||
<pre>
|
||||
Runnable myProxy = (Runnable) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
|
||||
new Class[] {Runnable.class}, (proxy, method, params) -> {
|
||||
System.out.println("Hello World!");
|
||||
return null;
|
||||
});
|
||||
InvocationHandler myHandler = (proxy, method, params) -> {
|
||||
System.out.println("Hello World!");
|
||||
<b>return</b> null;
|
||||
};
|
||||
Runnable myProxy = (Runnable) Proxy.newProxyInstance(
|
||||
Thread.currentThread().getContextClassLoader(),
|
||||
<b>new</b> Class[] {Runnable.class}, myHandler
|
||||
);
|
||||
</pre>
|
||||
<p>
|
||||
The code snippet above is designed to only proxy the <code>Runnable.run()</code> method. However, the calls to Object’s
|
||||
virtual methods are dispatched as well, which may lead to problems like <code>NullPointerException</code> on trying
|
||||
to add <code>myProxy</code> to a <code>HashSet</code>.
|
||||
The code snippet above is designed to only proxy the <code>Runnable.run()</code> method.
|
||||
However, calls to any <code>Object</code> methods, like <code>hashCode()</code>, are proxied as well.
|
||||
This can lead to problems like a <code>NullPointerException</code> when adding <code>myProxy</code> to a <code>HashSet</code> for example.
|
||||
</p>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2020.2</small>
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports non-abstract JUnit test cases which do not
|
||||
Reports non-<code>abstract</code> JUnit test cases which do not
|
||||
expose a public no-arg constructor or a public constructor which takes a single string
|
||||
as an argument. Such test cases will be unrunnable by most JUnit test runners, including
|
||||
IDEA's.
|
||||
as an argument. Such test cases will not be runnable by most JUnit test runners.
|
||||
<p>Example:
|
||||
<pre><code>
|
||||
public class MyTest {
|
||||
|
||||
private MyTest() {} // no-arg constructor is private
|
||||
|
||||
@Test
|
||||
public void testSomething() {
|
||||
assertEquals(1, 1);
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports on any unnecessary <b>return</b> statements at the end of constructors and methods returning
|
||||
<b>void</b>. These may be safely removed.
|
||||
<p>
|
||||
At present, this inspection is disabled in JSP files.
|
||||
Reports <code>return</code> statements at the end of constructors and methods returning
|
||||
<code>void</code>. These are unnecessary and may be safely removed.
|
||||
<p>This inspection does not report in JSP files.
|
||||
<p>Example:
|
||||
<pre>
|
||||
<b>void</b> message() {
|
||||
System.out.println("Hello World");
|
||||
<b>return</b>;
|
||||
}
|
||||
</pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre>
|
||||
<b>void</b> message() {
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
Use the checkbox below to let this inspection ignore <b>return</b> statements in the then branch of <b>if</b> statements
|
||||
which also have an <b>else</b> branch.
|
||||
<p>
|
||||
|
||||
Use the checkbox below to ignore <code>return</code> statements in the then branch of <code>if</code> statements
|
||||
which also have an <code>else</code> branch.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,8 +1,21 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports unnecessarily escaped characters in <b>String</b> and optionally <b>char</b> literals.
|
||||
For example <b>\'</b> in a <b>String</b> literal or <b>\n</b> in a Java 13 Preview text block.
|
||||
The escaped tab character <b>\t</b> is not reported.
|
||||
Reports unnecessarily escaped characters in <code>String</code> and optionally <code>char</code> literals.
|
||||
The escaped tab character <code>\t</code> is not reported, because it would otherwise be invisible.
|
||||
<p>Examples:
|
||||
<pre>
|
||||
String s = "\'Scare\' quotes";
|
||||
String t = """
|
||||
All you need is\n\tLove\n""";
|
||||
</pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre>
|
||||
String s = "'Scare' quotes";
|
||||
String t = """
|
||||
All you need is
|
||||
\tLove
|
||||
""";
|
||||
</pre>
|
||||
<!-- tooltip end -->
|
||||
<p><small>New in 2019.3</small>
|
||||
</body>
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
<html>
|
||||
<body>
|
||||
Reports unused code labels.
|
||||
Reports labels which are not the target of any <code>break</code> or <code>continue</code> statements.
|
||||
<p>For example:
|
||||
<pre><code>
|
||||
label: <b>for</b> (int i = 0; i < 10; i++) {
|
||||
<b>if</b> (i == 3) {
|
||||
<b>break</b>;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>After the quick fix is applied the result looks like:
|
||||
<pre><code>
|
||||
<b>for</b> (int i = 0; i < 10; i++) {
|
||||
<b>if</b> (i == 3) {
|
||||
<b>break</b>;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<!-- tooltip end -->
|
||||
<p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user