Issue #4981: ImportOrder with order=bottom should disallow non-static import after a static import
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
index a6f08bf..f769c75 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
@@ -392,6 +392,10 @@
             }
             doVisitToken(ident, isStatic, isStaticAndNotLastImport);
 
+            if (isStaticAndNotLastImport && !beforeFirstImport) {
+                log(ident.getLineNo(), MSG_ORDERING, ident.getText());
+            }
+
         }
         else if (option == ImportOrderOption.BOTTOM) {
 
@@ -401,6 +405,10 @@
             }
             doVisitToken(ident, isStatic, isLastImportAndNonStatic);
 
+            if (isLastImportAndNonStatic) {
+                log(ident.getLineNo(), MSG_ORDERING, ident.getText());
+            }
+
         }
         else if (option == ImportOrderOption.ABOVE) {
             // previous non-static but current is static
@@ -440,14 +448,15 @@
         final int groupIdx = getGroupNumber(name);
         final int line = ident.getLineNo();
 
-        if (isInSameGroup(groupIdx, isStatic)) {
-            doVisitTokenInSameGroup(isStatic, previous, name, line);
-        }
-        else if (groupIdx > lastGroup) {
-            if (!beforeFirstImport && separated && line - lastImportLine < 2) {
+        if (groupIdx > lastGroup) {
+            if (!beforeFirstImport && separated && line - lastImportLine < 2
+                && !isInSameGroup(groupIdx, isStatic)) {
                 log(line, MSG_SEPARATION, name);
             }
         }
+        else if (isInSameGroup(groupIdx, isStatic)) {
+            doVisitTokenInSameGroup(isStatic, previous, name, line);
+        }
         else {
             log(line, MSG_ORDERING, name);
         }
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java
index 0910437..7d33222 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java
@@ -409,6 +409,57 @@
     }
 
     @Test
+    public void testStaticGroupsAlphabeticalOrderBottomNegative() throws Exception {
+        final DefaultConfiguration checkConfig =
+            createModuleConfig(ImportOrderCheck.class);
+        checkConfig.addAttribute("option", "bottom");
+        checkConfig.addAttribute("groups", "org, java");
+        checkConfig.addAttribute("separated", "true");
+        checkConfig.addAttribute("sortStaticImportsAlphabetically", "true");
+        final String[] expected = {
+            "8: " + getCheckMessage(MSG_ORDERING, "java.util.Set"),
+        };
+        verify(checkConfig, getPath("InputImportOrderStaticGroupOrderBottom_Negative.java"),
+            expected);
+    }
+
+    /** Tests that a non-static import after a static import correctly gives an
+     * error if order=bottom. */
+
+    @Test
+    public void testStaticGroupsAlphabeticalOrderTopNegative() throws Exception {
+        final DefaultConfiguration checkConfig =
+            createModuleConfig(ImportOrderCheck.class);
+        checkConfig.addAttribute("option", "top");
+        checkConfig.addAttribute("groups", "org, java");
+        checkConfig.addAttribute("separated", "true");
+        checkConfig.addAttribute("sortStaticImportsAlphabetically", "true");
+        final String[] expected = {
+            "5: " + getCheckMessage(MSG_ORDERING, "java.lang.Math.PI"),
+        };
+        verify(checkConfig, getPath("InputImportOrderStaticGroupOrderBottom_Negative.java"),
+            expected);
+    }
+
+    /** Tests that a non-static import before a static import correctly gives an
+     * error if order=top. */
+
+    @Test
+    public void testStaticGroupsAlphabeticalOrderBottomNegative2() throws Exception {
+        final DefaultConfiguration checkConfig =
+            createModuleConfig(ImportOrderCheck.class);
+        checkConfig.addAttribute("option", "bottom");
+        checkConfig.addAttribute("groups", "org, java");
+        checkConfig.addAttribute("separated", "true");
+        checkConfig.addAttribute("sortStaticImportsAlphabetically", "true");
+        final String[] expected = {
+            "8: " + getCheckMessage(MSG_ORDERING, "java.util.Set"),
+        };
+        verify(checkConfig, getPath("InputImportOrderStaticGroupOrderBottom_Negative2.java"),
+            expected);
+    }
+
+    @Test
     public void testStaticGroupsOrderBottom() throws Exception {
         final DefaultConfiguration checkConfig =
             createModuleConfig(ImportOrderCheck.class);
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/importorder/InputImportOrderStaticGroupOrderBottom_Negative.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/importorder/InputImportOrderStaticGroupOrderBottom_Negative.java
new file mode 100644
index 0000000..e093b04
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/importorder/InputImportOrderStaticGroupOrderBottom_Negative.java
@@ -0,0 +1,13 @@
+package com.puppycrawl.tools.checkstyle.checks.imports.importorder;
+
+import org.*;
+
+import static java.lang.Math.PI;
+import static org.antlr.v4.runtime.Recognizer.EOF;
+
+import java.util.Set;
+
+public class InputImportOrderStaticGroupOrderBottom_Negative
+{
+
+}
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/importorder/InputImportOrderStaticGroupOrderBottom_Negative2.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/importorder/InputImportOrderStaticGroupOrderBottom_Negative2.java
new file mode 100644
index 0000000..61277ad
--- /dev/null
+++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/importorder/InputImportOrderStaticGroupOrderBottom_Negative2.java
@@ -0,0 +1,15 @@
+package com.puppycrawl.tools.checkstyle.checks.imports.importorder;
+
+import org.*;
+
+import static java.lang.Math.PI;
+import static org.antlr.v4.runtime.Recognizer.EOF;
+
+import java.util.Set;
+
+import static java.util.Set.*;
+
+public class InputImportOrderStaticGroupOrderBottom_Negative2
+{
+
+}