Changeset 19238 in josm for trunk/src/org


Ignore:
Timestamp:
2024-10-09T14:17:52+02:00 (6 weeks ago)
Author:
taylor.smock
Message:

See #23926: Fix new coverity issues

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.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java

    r19236 r19238  
    241241    /** maxTime saves the end time of the track as epoch seconds */
    242242    private double maxTime;
    243 
    244243
    245244    private void setupColors() {
  • trunk/src/org/openstreetmap/josm/tools/ColorScale.java

    r19236 r19238  
    1414import java.time.ZonedDateTime;
    1515import java.time.format.DateTimeFormatter;
     16import java.util.Objects;
    1617
    1718import org.openstreetmap.josm.data.preferences.NamedColorProperty;
     
    205206     */
    206207    public ColorScale addTitle(String title) {
     208        Objects.requireNonNull(title);
    207209        this.title = title;
    208210        return this;
     
    325327
    326328        // legend title
    327         if (title != null) {
    328             g.setColor(LEGEND_TITLE);
    329             g.drawString(title, xRect + rectWidth / 2 - titleWidth / 2, y - fh * 3 / 2 - 10);
    330         }
     329        g.setColor(LEGEND_TITLE);
     330        g.drawString(title, xRect + rectWidth / 2 - titleWidth / 2, y - fh * 3 / 2 - 10);
    331331
    332332        // legend texts
     
    385385
    386386        // legend title
    387         if (title != null) {
    388             g.setColor(LEGEND_TITLE);
    389             g.drawString(title, xRect + rectWidth / 2 - titleWidth / 2, y - fh * 3 / 2 - padding / 2);
    390         }
     387        g.setColor(LEGEND_TITLE);
     388        g.drawString(title, xRect + rectWidth / 2 - titleWidth / 2, y - fh * 3 / 2 - padding / 2);
    391389
    392390        // legend texts
Note: See TracChangeset for help on using the changeset viewer.