jts icon indicating copy to clipboard operation
jts copied to clipboard

Non-closed polygon parsing caused unexpected Exception

Open RiseOfDeath opened this issue 1 year ago • 1 comments

Demo code:

@ExtendWith(MockitoExtension.class)
public class WKTReadTest
{

    @Test
    void wrongGeometryTest() {
        String openPolygon = "POLYGON ((0 0, 1 1, 1 0))";
        var reader = new WKTReader();
        Assertions.assertThrows(ParseException.class, () -> reader.read(openPolygon));
    }
}

Expected :class org.locationtech.jts.io.ParseException Actual :class java.lang.IllegalArgumentException

Affected versions: 1.19.0 and 1.18.2, others not checked

RiseOfDeath avatar Feb 02 '24 08:02 RiseOfDeath

JTS considers this to be not a parsing error, but a malformed geometry error (which is what IllegalArgumentException indicates. So this is as per design. Just check for both errors.

dr-jts avatar Mar 14 '24 17:03 dr-jts