From a46b37aa9899131c56c2aefcc7af07a12e93453f Mon Sep 17 00:00:00 2001 From: rainer Date: Sat, 28 Dec 2024 21:53:04 +0100 Subject: [PATCH] #186 - LENIENT mode allows GPX tags without creator attributes --- README.md | 6 +++++ buildSrc/src/main/kotlin/Env.kt | 2 +- jpx/src/main/java/io/jenetics/jpx/GPX.java | 4 +-- .../test/java/io/jenetics/jpx/GPXTest.java | 27 +++++++++++++++++++ .../resources/io/jenetics/jpx/ISSUE-186.gpx | 16 +++++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 jpx/src/test/resources/io/jenetics/jpx/ISSUE-186.gpx diff --git a/README.md b/README.md index 5c69b328..8ebf3468 100644 --- a/README.md +++ b/README.md @@ -330,6 +330,12 @@ The library is licensed under the [Apache License, Version 2.0](http://www.apach ## Release notes +#### Improvements + +* [#186](https://github.com/jenetics/jpx/issues/186): LENIENT mode allows GPX tags without creator attributes. + +### 3.2.1 + ### [3.2.0](https://github.com/jenetics/jpx/releases/tag/v3.2.0) #### Improvements diff --git a/buildSrc/src/main/kotlin/Env.kt b/buildSrc/src/main/kotlin/Env.kt index 84cd47b8..24b4e7c3 100644 --- a/buildSrc/src/main/kotlin/Env.kt +++ b/buildSrc/src/main/kotlin/Env.kt @@ -52,7 +52,7 @@ object Env { * Information about the library and author. */ object JPX { - const val VERSION = "3.2.0" + const val VERSION = "3.2.1" const val ID = "jpx" const val NAME = "jpx" const val GROUP = "io.jenetics" diff --git a/jpx/src/main/java/io/jenetics/jpx/GPX.java b/jpx/src/main/java/io/jenetics/jpx/GPX.java index 4792a20a..31ee5b15 100644 --- a/jpx/src/main/java/io/jenetics/jpx/GPX.java +++ b/jpx/src/main/java/io/jenetics/jpx/GPX.java @@ -309,7 +309,7 @@ public static Version of(final String version) { * @param routes the routes * @param tracks the tracks * @param extensions the XML extensions document - * @throws NullPointerException if the {@code creator} or {@code version} is + * @throws NullPointerException if the {@code version} is * {@code null} */ private GPX( @@ -322,7 +322,7 @@ private GPX( final Document extensions ) { _version = requireNonNull(version); - _creator = requireNonNull(creator); + _creator = creator; _metadata = metadata; _wayPoints = copyOf(wayPoints); _routes = copyOf(routes); diff --git a/jpx/src/test/java/io/jenetics/jpx/GPXTest.java b/jpx/src/test/java/io/jenetics/jpx/GPXTest.java index 22735862..dd74ce5d 100644 --- a/jpx/src/test/java/io/jenetics/jpx/GPXTest.java +++ b/jpx/src/test/java/io/jenetics/jpx/GPXTest.java @@ -960,4 +960,31 @@ public void issue170_InvalidGPXVersion() throws IOException { assertThat(gpx.getTracks().get(0).getSegments().get(0)).hasSize(2); } + @Test + public void issue186_MissingCreator() throws IOException { + final var resource = "/io/jenetics/jpx/ISSUE-186.gpx"; + final GPX gpx_lenient; + try (InputStream in = getClass().getResourceAsStream(resource)) { + gpx_lenient = GPX.Reader.of(Mode.LENIENT).read(in); + } + + assertThat(gpx_lenient.getVersion()).isEqualTo("1.1"); + assertThat(gpx_lenient.getCreator()).isNull(); + assertThat(gpx_lenient.getTracks()).hasSize(1); + assertThat(gpx_lenient.getTracks().get(0).getSegments()).hasSize(1); + assertThat(gpx_lenient.getTracks().get(0).getSegments().get(0)).hasSize(9); + + + try (InputStream in = getClass().getResourceAsStream("/path/to/resource")) { + GPX.Reader.of(Mode.STRICT).read(in); + Assert.fail("Expected InvalidObjectException to be thrown."); + } catch (NullPointerException e) { + // Expected to fail in STRICT mode, as Creator attribute is missing + } catch (Exception e) { + Assert.fail("Unexpected exception was thrown: " + e); + } + + + } + } diff --git a/jpx/src/test/resources/io/jenetics/jpx/ISSUE-186.gpx b/jpx/src/test/resources/io/jenetics/jpx/ISSUE-186.gpx new file mode 100644 index 00000000..7a718a05 --- /dev/null +++ b/jpx/src/test/resources/io/jenetics/jpx/ISSUE-186.gpx @@ -0,0 +1,16 @@ + + + + + 1411.7906106047938 + 1392.486126435269 + 1395.0386210201773 + 1399.1852111777555 + 1400.9042412783833 + 1404.8712068295272 + 1406.7036626781644 + 1408.6363346678631 + 1410.9618086711207 + + +