Index: trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java	(revision 18495)
+++ trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java	(revision 18496)
@@ -1290,7 +1290,10 @@
         }
 
-        private Nth(int nth, boolean modulo) {
+        private Nth(int nth, boolean modulo) throws SearchParseError {
             this.nth = nth;
             this.modulo = modulo;
+            if (this.modulo && this.nth == 0) {
+                throw new SearchParseError(tr("Non-zero integer expected"));
+            }
         }
 
Index: trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java
===================================================================
--- trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java	(revision 18495)
+++ trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java	(revision 18496)
@@ -851,3 +851,12 @@
         assertFalse(c.match(OsmUtils.createPrimitive("node name=bar")));
     }
+
+    /**
+     * Non-regression test for JOSM #22156
+     * x % 0 throws an ArithmeticException
+     */
+    @Test
+    void testNonRegression22156() {
+        assertThrows(SearchParseError.class, () -> SearchCompiler.compile("nth%: 0"));
+    }
 }
