Skip to content

fix(data)!: declare IOException on data parser entry points - #1835

Open
kikoso wants to merge 1 commit into
mainfrom
fix/parser-throws-ioexception
Open

kikoso wants to merge 1 commit into
mainfrom
fix/parser-throws-ioexception

Conversation

@kikoso

@kikoso kikoso commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1834

The data parsers propagate IOException at runtime (stream failures, and for KMZ the entry count and uncompressed size limits), but their Java signatures did not declare it. Java callers could not write catch (IOException e) around a parse call and had to catch Exception instead.

This adds @Throws(IOException::class) to the public entry points:

  • KmzParser.parse
  • KmlParser.parse and KmlParser.parseAsKml
  • GpxParser.parse
  • GeoJsonParser.parse

I annotated the existing methods instead of adding a separate parseChecked() method. A second method doing the same thing adds API surface for little gain, and v7.0.0 is already a breaking release.

Compatibility

  • Kotlin callers are unaffected.
  • Binary compatible: already-compiled Java code keeps working.
  • Source-breaking for Java: callers that recompile must catch or declare IOException. Documented in MIGRATION.md (section 6), hence the !.

Tests

ParserCheckedExceptionTest is written in Java, so each catch (IOException e) only compiles if the method declares the exception. It also checks that a stream read failure reaches that catch.

  • ./gradlew :data:testDebugUnitTest: 192 tests, 0 failures
  • ./gradlew :data:lintDebug spotlessCheck: passing

KmzParser, KmlParser, GpxParser and GeoJsonParser propagate IOException
at runtime but did not declare it, so Java callers could not catch it
specifically. Annotate the public parse entry points with @throws.

Fixes #1834
@googlemaps-bot

Copy link
Copy Markdown
Contributor

Code Coverage

Overall Project 62.53% 🍏
Module Coverage
Kover Gradle Plugin XML report for :data 61.12% 🍏
Files
Module File Coverage
Kover Gradle Plugin XML report for :data KmlParser.kt 90.53% 🍏
GpxParser.kt 88.68% 🍏
GeoJsonParser.kt 88.24% 🍏
KmzParser.kt 87.85% 🍏

@kikoso
kikoso marked this pull request as ready for review October 27, 2026 04:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java callers cannot specifically catch IOException from KmzParser.parse

3 participants