Ignore:
Timestamp:
2023-06-13T22:36:12+02:00 (12 months ago)
Author:
taylor.smock
Message:

Fix #23001: ClassCastException in GpxDrawHelper#calculateColors

This occurs when a working GPX file with HDOP information is converted to an OSM
Data Layer and back to a GPX Data Layer. This is fixed by (a) converting casts
for get operations to Number instead of Float/Integer and (b) actually
putting the number in the attribute map instead of a string.

File:
1 edited

Legend:

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

    r18742 r18753  
    626626        }
    627627
    628         ArrayList<String> refs = new ArrayList<String>();
     628        ArrayList<String> refs = new ArrayList<>();
    629629        if (colored == ColorMode.REF) {
    630630            for (Line segment : getLinesIterable(null)) {
     
    639639                }
    640640            }
    641             if (refs.size() > 0) {
     641            if (!refs.isEmpty()) {
    642642                Collections.sort(refs);
    643643                String[] a = {};
     
    660660
    661661                if (colored == ColorMode.HDOP) {
    662                     color = hdopScale.getColor((Float) trkPnt.get(GpxConstants.PT_HDOP));
     662                    color = hdopScale.getColor((Number) trkPnt.get(GpxConstants.PT_HDOP));
    663663                } else if (colored == ColorMode.QUALITY) {
    664                     color = qualityScale.getColor((Integer) trkPnt.get(GpxConstants.RTKLIB_Q));
     664                    color = qualityScale.getColor((Number) trkPnt.get(GpxConstants.RTKLIB_Q));
    665665                } else if (colored == ColorMode.FIX) {
    666666                    Object fixval = trkPnt.get(GpxConstants.PT_FIX);
     
    671671                        }
    672672                    }
    673                 } else if (colored == ColorMode.REF) {
    674                     if (trkPnt.get(GpxConstants.PT_DGPSID) != null) {
    675                         String refval = trkPnt.get(GpxConstants.PT_DGPSID).toString();
    676                         int i = refs.indexOf(refval);
    677                         if (i >= 0) {
    678                             color = refScale.getColor(i);
    679                         }
     673                } else if (colored == ColorMode.REF && trkPnt.get(GpxConstants.PT_DGPSID) != null) {
     674                    String refVal = trkPnt.get(GpxConstants.PT_DGPSID).toString();
     675                    int i = refs.indexOf(refVal);
     676                    if (i >= 0) {
     677                        color = refScale.getColor(i);
    680678                    }
    681679                }
     
    852850                if (hdopCircle && trkPnt.get(GpxConstants.PT_HDOP) != null) {
    853851                    // hdop value
    854                     float hdop = (Float) trkPnt.get(GpxConstants.PT_HDOP);
     852                    float hdop = ((Number) trkPnt.get(GpxConstants.PT_HDOP)).floatValue();
    855853                    if (hdop < 0) {
    856854                        hdop = 0;
Note: See TracChangeset for help on using the changeset viewer.