diff --git a/java/java-impl/src/inspectionDescriptions/SuspiciousListRemoveInLoop.html b/java/java-impl/src/inspectionDescriptions/SuspiciousListRemoveInLoop.html index 58435361fc5e..d1f561059029 100644 --- a/java/java-impl/src/inspectionDescriptions/SuspiciousListRemoveInLoop.html +++ b/java/java-impl/src/inspectionDescriptions/SuspiciousListRemoveInLoop.html @@ -1,10 +1,27 @@ -Reports when list.remove(index) is called inside the ascending counted loop. This is suspicious as list becomes -shorter after that and the element next to removed will not be processed. Simple fix is to decrease the index variable after removal, -but probably removing via iterator or using removeIf method (since Java 8) is a more robust alternative. -If you don't expect that remove will be called more than once in a loop, consider adding a break command -after it. +Reports when list.remove(index) is called inside the ascending counted loop. This is suspicious as list becomes +shorter after that, and the element next to removed will not be processed. A simple fix is to decrease the index variable after removal, +but probably removing via iterator or using removeIf method (since Java 8) is a more robust alternative. +If you don't expect that remove will be called more than once in a loop, consider adding a break after it. + +

Example:

+
+  public static void main(String[] args) {
+    process(new ArrayList<>(Arrays.asList("1", "2", "|", "3", "4")));
+  }
+
+  static void process(List<String> list) {
+    for (int i = 0; i < list.size(); i++) {
+      if (list.get(i).equals("|")) {
+        list.remove(i);
+        continue;
+      }
+      System.out.println(list.get(i));
+    }
+  }
+
+

Here we could expect that '1 2 3 4' will be printed, but 3 will be skipped in the output.

New in 2018.2

diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/CollectionAddedToSelf.html b/plugins/InspectionGadgets/src/inspectionDescriptions/CollectionAddedToSelf.html index 66fee1dd36dc..9e6614acb304 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/CollectionAddedToSelf.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/CollectionAddedToSelf.html @@ -1,9 +1,17 @@ -Reports cases where the argument of a method call on a java.util.Collection -or java.util.Map is the collection or map itself. -This includes adding a collection to itself, which can lead to a java.lang.StackOverflowError when, -for example, calling hashCode() on the self-containing collection. +Reports cases where the argument of a method call on a java.util.Collection +or java.util.Map is the collection or map itself. +This includes adding a collection to itself, which can lead to a java.lang.StackOverflowError when, +for example, calling hashCode() on the self-containing collection. +May happen in the code with raw types as a result of copy-paste. + +

Example:

+
+  ArrayList list = new ArrayList<>();
+  list.add(list);
+  return list.hashCode(); // throws StackOverflowException
+

diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceAllDot.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceAllDot.html index 6502f8e256fa..831b9d743b49 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceAllDot.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ReplaceAllDot.html @@ -1,10 +1,19 @@ Reports any calls to -String.replaceAll() or String.split() where the first argument is a single regex meta character argument. +String.replaceAll() or String.split() where the first argument is a single regex meta character argument. The regex meta characters are one of ".$|()[{^?*+\", and these have a special meaning in regular expressions. -For example calling "ab.cd".replaceAll(".", "-") produces "-----", because the dot matches any character. -Most likely the escaped variant "\\." was intended instead. +For example calling "ab.cd".replaceAll(".", "-") produces "-----", because the dot matches any character. +Most likely the escaped variant "\\." was intended instead. + +

Example:

+
+  s.replaceAll(".", "-");
+
+

After the quick-fix is applied the result looks like:

+
+  s.replaceAll("\\.", "-");
+

diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ThreadRun.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ThreadRun.html index 12b1305b5d14..4a1781810c0e 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/ThreadRun.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ThreadRun.html @@ -1,7 +1,7 @@ -Reports any calls to run() on java.lang.Thread or any of its subclasses. -While occasionally intended, this is usually a mistake, with start() intended instead. +Reports any calls to run() on java.lang.Thread or any of its subclasses because run() doesn't start a new thread. +While occasionally intended, this is usually a mistake, with start() intended instead.

diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/ThrowableNotThrown.html b/plugins/InspectionGadgets/src/inspectionDescriptions/ThrowableNotThrown.html index 9a5374999f9d..0530ba7b5d61 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/ThrowableNotThrown.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/ThrowableNotThrown.html @@ -1,9 +1,16 @@ -Reports instantiations of Throwable and subclasses, where the created Throwable -is never actually thrown. Also reports method calls which return Throwable instances, +Reports instantiations of Throwable and subclasses, where the created Throwable +is never actually thrown. Also reports method calls which return Throwable instances, where the result of the method call is not thrown. These are simple mistakes to make which are hard to catch in tests. +

Example:

+
+    void leftBehind() throws Throwable {
+        RuntimeException e = new RuntimeException("throw me");
+        // ...
+    }
+

diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/UnnecessaryDefault.html b/plugins/InspectionGadgets/src/inspectionDescriptions/UnnecessaryDefault.html index 9d760512e488..8025921fc7ee 100644 --- a/plugins/InspectionGadgets/src/inspectionDescriptions/UnnecessaryDefault.html +++ b/plugins/InspectionGadgets/src/inspectionDescriptions/UnnecessaryDefault.html @@ -1,12 +1,36 @@ -Reports enum switch statements or expression with default branches which can never be taken, -because all possible values are covered by a case branch. -These are unnecessary, especially for switch expressions, because they don't compile when all -enum constants are not covered by a case branch. +Reports enum switch statements or expression with default branches which can never be taken, +because all possible values are covered by a case branch. +These are unnecessary, especially for switch expressions, because they don't compile when all +enum constants are not covered by a case branch.

- The language level needs to be configured to 13 Preview to report switch expressions. + The language level needs to be configured to 13 Preview to report switch expressions. +

+Quick fix removes default branch. +

Example:

+
+  enum E { A, B }
+  int foo(E e) {
+    return = switch (e) {
+      case A -> 1;
+      case B -> 2;
+      default -> 3;
+    };
+  }
+
+

After the quick-fix is applied the result looks like:

+
+  enum E { A, B }
+  int foo(E e) {
+    return = switch (e) {
+      case A -> 1;
+      case B -> 2;
+    };
+  }
+
+

Use option to report only unnecessary default branches in switch expressions

diff --git a/plugins/testng/resources/inspectionDescriptions/DataProviderReturnType.html b/plugins/testng/resources/inspectionDescriptions/DataProviderReturnType.html index d51ecde7cf56..994e80b512ff 100644 --- a/plugins/testng/resources/inspectionDescriptions/DataProviderReturnType.html +++ b/plugins/testng/resources/inspectionDescriptions/DataProviderReturnType.html @@ -1,6 +1,6 @@ -Inspection checks that method which is marked with @DataProvider annotation -returns Object[][] or Iterator<Object>. +Reports methods marked with @DataProvider annotation which returns not Object[][] or Iterator<Object>. +If other type is returned, TestNG will throw an exception. \ No newline at end of file