Skip to content

Commit

Permalink
prevent NPEs by selectively executing draw commands
Browse files Browse the repository at this point in the history
  • Loading branch information
edeso committed Aug 28, 2022
1 parent ec02bca commit c942f41
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,24 @@ public void add(Listener listener) {
* @param command undoable command to execute
*/
protected void execute(UndoableCommand command) {
execute(command, false);
}

/**
* Optional means of execution, with undoability.
* Allows to ignore when command is null in case the calling code already warns
* user accordingly.
*
* @param command
* @param ignoreNull
*/
protected void execute(UndoableCommand command, boolean ignoreNull) {
if (command == null) {
if (ignoreNull)
return;
else
throw new IllegalArgumentException("UndoableCommand command must not be null.");
}
AbstractPlugIn.execute(command, getPanel());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected void gestureFinished() throws Exception {
getPoint(),
isRollingBackInvalidEdits(),
getPanel(),
this));
this),true);
}

protected Point getPoint()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -158,6 +159,7 @@ public UndoableCommand createAddCommand(final Geometry geometry,
.getContext()
.warnUser(
I18N.getInstance().get("ui.cursortool.editing.FeatureDrawingUtil.draw-feature-tool-topology-error"));
Logger.error(new InvalidParameterException("Parameter geometry is not valid according to jts."));
return null;
}
// Don't want viewport to change at this stage. [Jon Aquino]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected void gestureFinished() throws Exception {
}

execute(featureDrawingUtil.createAddCommand(getCircle(),
isRollingBackInvalidEdits(), getPanel(), this));
isRollingBackInvalidEdits(), getPanel(), this),true);
}

protected Polygon getCircle() throws NoninvertibleTransformException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected void gestureFinished() throws Exception {
}

execute(featureDrawingUtil.createAddCommand(getLineString(),
isRollingBackInvalidEdits(), getPanel(), this));
isRollingBackInvalidEdits(), getPanel(), this),true);
}

protected LineString getLineString() throws NoninvertibleTransformException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ else if (polygon!=null && !polygon.isEmpty()) {
context.getWorkbench().getFrame().warnUser(INTERRUPTION);
} else if (!polygon.isEmpty()) {
execute(featureDrawingUtil.createAddCommand(polygon,
isRollingBackInvalidEdits(), getPanel(), this));
isRollingBackInvalidEdits(), getPanel(), this),true);
} else {
context.getWorkbench().getFrame().warnUser(AREA_NOT_CLOSED);
}
Expand Down

0 comments on commit c942f41

Please sign in to comment.