Changeset 10309 in josm


Ignore:
Timestamp:
2016-06-02T00:26:31+02:00 (9 years ago)
Author:
Don-vip
Message:

sonar - squid:S1182 - Classes that override "clone" should be "Cloneable" and call "super.clone()"

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r10040 r10309  
    132132     */
    133133    public DataSet() {
    134         /*
    135          * Transparently register as projection change lister. No need to explicitly remove the
    136          * the listener, projection change listeners are managed as WeakReferences.
    137          */
     134        // Transparently register as projection change listener. No need to explicitly remove
     135        // the listener, projection change listeners are managed as WeakReferences.
    138136        Main.addProjectionChangeListener(this);
    139137    }
     
    879877        getReadLock().lock();
    880878        try {
    881             DataSet ds = new DataSet();
     879            DataSet ds = (DataSet) super.clone();
     880            Main.addProjectionChangeListener(ds);
    882881            Map<OsmPrimitive, OsmPrimitive> primMap = new HashMap<>();
    883882            for (Node n : nodes) {
     
    917916            ds.version = version;
    918917            return ds;
     918        } catch (CloneNotSupportedException e) {
     919            throw new IllegalStateException(e);
    919920        } finally {
    920921            getReadLock().unlock();
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java

    r10212 r10309  
    312312    @Override
    313313    public ImageEntry clone() {
    314         Object c;
    315         try {
    316             c = super.clone();
     314        try {
     315            return (ImageEntry) super.clone();
    317316        } catch (CloneNotSupportedException e) {
    318             throw new RuntimeException(e);
    319         }
    320         return (ImageEntry) c;
     317            throw new IllegalStateException(e);
     318        }
    321319    }
    322320
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java

    r10300 r10309  
    197197    @Override
    198198    public Cascade clone() {
    199         @SuppressWarnings("unchecked")
    200         Map<String, Object> clonedProp = (Map<String, Object>) ((HashMap) this.prop).clone();
    201         Cascade c = new Cascade();
    202         c.prop = clonedProp;
    203         return c;
     199        try {
     200            Cascade c = (Cascade) super.clone();
     201            @SuppressWarnings({ "unchecked", "rawtypes" })
     202            Map<String, Object> clonedProp = (Map<String, Object>) ((HashMap) this.prop).clone();
     203            c.prop = clonedProp;
     204            return c;
     205        } catch (CloneNotSupportedException e) {
     206            throw new IllegalStateException(e);
     207        }
    204208    }
    205209
  • trunk/src/org/openstreetmap/josm/tools/CopyList.java

    r9997 r10309  
    1818 * @param <E> the type of elements in this list
    1919 */
    20 public final class CopyList<E> extends AbstractList<E> implements RandomAccess, Cloneable {
     20public final class CopyList<E> extends AbstractList<E> implements RandomAccess {
    2121    private E[] array;
    2222    private int size;
     
    113113
    114114    // helpers:
    115     /**
    116      * Returns another independent copy-on-write copy of this <tt>List</tt>
    117      * instance. Neither the elements nor the backing storage are copied.
    118      *
    119      * @return a clone of this <tt>CopyList</tt> instance
    120      */
    121     @Override
    122     public Object clone() {
    123         return new CopyList<>(array, size);
    124     }
    125115
    126116    private void rangeCheck(int index) {
Note: See TracChangeset for help on using the changeset viewer.