Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnaryUnionOp throws NPE on [POINT EMPTY, LINESTRING(0 0, 1 1)] #490

Closed
jagill opened this issue Oct 25, 2019 · 3 comments
Closed

UnaryUnionOp throws NPE on [POINT EMPTY, LINESTRING(0 0, 1 1)] #490

jagill opened this issue Oct 25, 2019 · 3 comments

Comments

@jagill
Copy link

jagill commented Oct 25, 2019

When performing a union on an empty point with a linestring, UnaryUnionOp.union throws a NullPointerException. Code snippet at the bottom. The issue is:

  1. union first performs a partial union for each geometry dimension (this leaves the arguments unchanged in this case) then performs the Linear and Planar geometry unions.
  2. When it attempts to union the Puntal geometries with the Linear/Planar, it iterates through each point, getting its position.
  3. But the position of an empty point is null, so when the envelope check is performed against the position, the p.x access throws an NPE.

This could be fixed by adding after PointGeometryUnion line 62

    Point point = (Point) pointGeom.getGeometryN(i);
    if (point.isEmpty()) continue;

Alternatively, the Envelope containment check could have a null guard, if we can assume that a null position is never contained in an Envelope.

Repro code snippet:

WKTReader reader = new WKTReader();
Geometry emptyPoint = reader.read("POINT EMPTY");
Geometry lineString = reader.read("LINESTRING (0 0, 1 1)");
Geometry union = UnaryUnionOp.union(ImmutableList.of(emptyPoint, lineString));  // NPE
@dr-jts
Copy link
Contributor

dr-jts commented Oct 25, 2019

What version are you using? I think this is fixed in master as of #484.

@jagill
Copy link
Author

jagill commented Oct 25, 2019

I'm using 1.16.1, which is the latest, I think? I'm glad this has already been fixed! What's the release schedule?

@jagill
Copy link
Author

jagill commented Oct 25, 2019

I've confirmed that current master fixes this problem. Thanks!

@jagill jagill closed this as completed Oct 25, 2019
@jagill jagill mentioned this issue Jan 12, 2020
5 tasks
jagill added a commit to jagill/presto that referenced this issue Jul 23, 2020
This includes two bugfixes that block a serialization improvement.
1.17.0 also includes an improved Geometry.buffer() implementation,
and the current implementation has been causing memory issues for
large polygons.

The bugfixes include one for an
[NPE in UnaryUnionOp](locationtech/jts#490)
and one that used 3-dimensions, not 2, when deserializing WKTs into
a PackedCoordinateSequence.
mbasmanova pushed a commit to prestodb/presto that referenced this issue Jul 27, 2020
This includes two bugfixes that block a serialization improvement.
1.17.0 also includes an improved Geometry.buffer() implementation,
and the current implementation has been causing memory issues for
large polygons.

The bugfixes include one for an
[NPE in UnaryUnionOp](locationtech/jts#490)
and one that used 3-dimensions, not 2, when deserializing WKTs into
a PackedCoordinateSequence.
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

No branches or pull requests

2 participants