Changeset 18496 in josm


Ignore:
Timestamp:
2022-06-21T18:31:54+02:00 (22 months ago)
Author:
taylor.smock
Message:

Fix #22156: ArithmeticException: / by zero in org.openstreetmap.josm.data.osm.search.SearchCompiler$Nth.match

This was caused by nth%: 0, as x % 0 will throw a divide by 0
exception.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/search/SearchCompiler.java

    r18494 r18496  
    12901290        }
    12911291
    1292         private Nth(int nth, boolean modulo) {
     1292        private Nth(int nth, boolean modulo) throws SearchParseError {
    12931293            this.nth = nth;
    12941294            this.modulo = modulo;
     1295            if (this.modulo && this.nth == 0) {
     1296                throw new SearchParseError(tr("Non-zero integer expected"));
     1297            }
    12951298        }
    12961299
  • trunk/test/unit/org/openstreetmap/josm/data/osm/search/SearchCompilerTest.java

    r18291 r18496  
    851851        assertFalse(c.match(OsmUtils.createPrimitive("node name=bar")));
    852852    }
     853
     854    /**
     855     * Non-regression test for JOSM #22156
     856     * x % 0 throws an ArithmeticException
     857     */
     858    @Test
     859    void testNonRegression22156() {
     860        assertThrows(SearchParseError.class, () -> SearchCompiler.compile("nth%: 0"));
     861    }
    853862}
Note: See TracChangeset for help on using the changeset viewer.