Changeset 6222 in josm for trunk


Ignore:
Timestamp:
2013-09-08T05:14:39+02:00 (11 years ago)
Author:
Don-vip
Message:

Make some more defensive copies of user-supplied arrays, javadoc

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2SubGrid.java

    r6135 r6222  
    2323import java.io.InputStream;
    2424import java.io.Serializable;
     25
     26import org.openstreetmap.josm.tools.Utils;
    2527
    2628/**
     
    216218     * @param gs GridShift object containing the coordinate to shift and the shift values
    217219     * @return the GridShift object supplied, with values updated.
    218      * @throws IOException
    219220     */
    220221    public NTV2GridShift interpolateGridShift(NTV2GridShift gs) {
     
    281282     */
    282283    public void setSubGridArray(NTV2SubGrid[] subGrid) {
    283         this.subGrid = subGrid;
     284        this.subGrid = Utils.copyArray(subGrid);
    284285    }
    285286
     
    369370        return minLon;
    370371    }
    371 
    372372}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ComparePairType.java

    r5903 r6222  
    55import static org.openstreetmap.josm.gui.conflict.pair.ListRole.THEIR_ENTRIES;
    66import static org.openstreetmap.josm.tools.I18n.tr;
     7
     8import org.openstreetmap.josm.tools.Utils;
    79
    810/**
     
    3335    ComparePairType(String displayName, ListRole[] participatingRoles) {
    3436        this.displayName = displayName;
    35         this.participatingRoles = participatingRoles;
     37        this.participatingRoles = Utils.copyArray(participatingRoles);
    3638    }
    3739
  • trunk/src/org/openstreetmap/josm/gui/history/TwoColumnDiff.java

    r5627 r6222  
    88import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType;
    99import org.openstreetmap.josm.tools.Diff;
     10import org.openstreetmap.josm.tools.Utils;
    1011
    1112/**
     
    5455    Object[] current;
    5556
    56     /**
    57      * The arguments will _not_ be modified
    58      */
    5957    public TwoColumnDiff(Object[] reference, Object[] current) {
    60         this.reference = reference;
    61         this.current = current;
     58        this.reference = Utils.copyArray(reference);
     59        this.current = Utils.copyArray(current);
    6260        referenceDiff = new ArrayList<Item>();
    6361        currentDiff = new ArrayList<Item>();
    6462        diff();
    6563    }
     64   
    6665    private void diff() {
    6766        Diff diff = new Diff(reference, current);
     
    8281            int inserted = script.inserted;
    8382            while(ia < script.line0 && ib < script.line1){
    84                 // System.out.println(" "+a[ia] + "\t "+b[ib]);
    8583                Item cell = new Item(DiffItemType.SAME, a[ia]);
    8684                referenceDiff.add(cell);
     
    9290            while(inserted > 0 || deleted > 0) {
    9391                if(inserted > 0 && deleted > 0) {
    94                     // System.out.println("="+a[ia] + "\t="+b[ib]);
    9592                    referenceDiff.add(new Item(DiffItemType.CHANGED, a[ia++]));
    9693                    currentDiff.add(new Item(DiffItemType.CHANGED, b[ib++]));
    9794                } else if(inserted > 0) {
    98                     // System.out.println("\t+" + b[ib]);
    9995                    referenceDiff.add(new Item(DiffItemType.EMPTY, null));
    10096                    currentDiff.add(new Item(DiffItemType.INSERTED, b[ib++]));
    10197                } else if(deleted > 0) {
    102                     // System.out.println("-"+a[ia]);
    10398                    referenceDiff.add(new Item(DiffItemType.DELETED, a[ia++]));
    10499                    currentDiff.add(new Item(DiffItemType.EMPTY, null));
     
    110105        }
    111106        while(ia < a.length && ib < b.length) {
    112             // System.out.println((ia < a.length ? " "+a[ia]+"\t" : "\t") + (ib < b.length ? " "+b[ib] : ""));
    113107            referenceDiff.add(new Item(DiffItemType.SAME, a[ia++]));
    114108            currentDiff.add(new Item(DiffItemType.SAME, b[ib++]));
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ListProjectionChoice.java

    r5548 r6222  
    1212import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    1313import org.openstreetmap.josm.tools.GBC;
     14import org.openstreetmap.josm.tools.Utils;
    1415
    1516/**
     
    2425
    2526    /**
    26      * Constructor
     27     * Constructs a new {@code ListProjectionChoice}.
    2728     *
    2829     * @param name the display name
     
    3435    public ListProjectionChoice(String name, String id, Object[] entries, String label, int defaultIndex) {
    3536        super(name, id);
    36         this.entries = entries;
     37        this.entries = Utils.copyArray(entries);
    3738        this.label = label;
    3839        this.defaultIndex = defaultIndex;
    3940    }
    4041
     42    /**
     43     * Constructs a new {@code ListProjectionChoice}.
     44     * @param name the display name
     45     * @param id the unique id for this ProjectionChoice
     46     * @param entries the list of display entries for the combo-box
     47     * @param label a label shown left to the combo-box
     48     */
    4149    public ListProjectionChoice(String name, String id, Object[] entries, String label) {
    4250        this(name, id, entries, label, 0);
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentResponse.java

    r5692 r6222  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.io.auth;
     3
     4import org.openstreetmap.josm.tools.Utils;
    35
    46/**
     
    4244     */
    4345    public void setPassword(char[] password) {
    44         this.password = password;
     46        this.password = Utils.copyArray(password);
    4547    }
    4648    /**
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6221 r6222  
    256256   
    257257    /**
     258     * Copies the given array. Unlike {@link Arrays#copyOf}, this method is null-safe.
     259     * @param array The array to copy
     260     * @return A copy of the original array, or {@code null} if {@code array} is null
     261     * @since 6222
     262     */
     263    public static char[] copyArray(char[] array) {
     264        if (array != null) {
     265            return Arrays.copyOf(array, array.length);
     266        }
     267        return null;
     268    }
     269   
     270    /**
    258271     * Simple file copy function that will overwrite the target file.<br/>
    259272     * Taken from <a href="http://www.rgagnon.com/javadetails/java-0064.html">this article</a> (CC-NC-BY-SA)
     
    715728        return all.toString();
    716729    }
    717 
    718730}
Note: See TracChangeset for help on using the changeset viewer.