Skip to content

Commit

Permalink
See #23926: Fix new coverity issues
Browse files Browse the repository at this point in the history
Coverity doesn't like `null` checks when a previous statement would have thrown
a `NullPointerException` on the object being checked for `null`. This fixes the
"defect" by removing the `null` checks and adding a `null` check in
`ColorScale#addTitle`.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@19238 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Oct 9, 2024
1 parent fdef06a commit d8a97dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public class GpxDrawHelper implements SoMChangeListener, MapViewPaintable.LayerP
/** maxTime saves the end time of the track as epoch seconds */
private double maxTime;


private void setupColors() {
hdopAlpha = Config.getPref().getInt("hdop.color.alpha", -1);
velocityScale = ColorScale.createHSBScale(256);
Expand Down
14 changes: 6 additions & 8 deletions src/org/openstreetmap/josm/tools/ColorScale.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

import org.openstreetmap.josm.data.preferences.NamedColorProperty;

Expand Down Expand Up @@ -204,6 +205,7 @@ public ColorScale makeTransparent(int alpha) {
* @return This scale, for chaining
*/
public ColorScale addTitle(String title) {
Objects.requireNonNull(title);
this.title = title;
return this;
}
Expand Down Expand Up @@ -324,10 +326,8 @@ public void drawColorBar(final Graphics2D g, final int x, final int y, final int
}

// legend title
if (title != null) {
g.setColor(LEGEND_TITLE);
g.drawString(title, xRect + rectWidth / 2 - titleWidth / 2, y - fh * 3 / 2 - 10);
}
g.setColor(LEGEND_TITLE);
g.drawString(title, xRect + rectWidth / 2 - titleWidth / 2, y - fh * 3 / 2 - 10);

// legend texts
drawLegend(g, y, w, h, valueScale, fh, fw, xText);
Expand Down Expand Up @@ -384,10 +384,8 @@ public void drawColorBarTime(final Graphics2D g, final int x, final int y, final
}

// legend title
if (title != null) {
g.setColor(LEGEND_TITLE);
g.drawString(title, xRect + rectWidth / 2 - titleWidth / 2, y - fh * 3 / 2 - padding / 2);
}
g.setColor(LEGEND_TITLE);
g.drawString(title, xRect + rectWidth / 2 - titleWidth / 2, y - fh * 3 / 2 - padding / 2);

// legend texts
drawTimeLegend(g, y, x, h, minVal, maxVal, fh, fw, xText);
Expand Down

0 comments on commit d8a97dc

Please sign in to comment.