Changeset 10946 in josm


Ignore:
Timestamp:
2016-09-03T20:01:46+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13395 - fix serialization issue causing bugs in copy/paste

Location:
trunk
Files:
2 edited

Legend:

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

    r10868 r10946  
    3030    }
    3131
     32    /**
     33     * Constructs a new {@code PrimitiveData} from an existing one.
     34     * @param data the data to copy
     35     */
    3236    public PrimitiveData(PrimitiveData data) {
    3337        cloneFrom(data);
    3438    }
    3539
     40    /**
     41     * Sets the primitive identifier.
     42     * @param id primitive identifier
     43     */
    3644    public void setId(long id) {
    3745        this.id = id;
    3846    }
    3947
     48    /**
     49     * Sets the primitive version.
     50     * @param version primitive version
     51     */
    4052    public void setVersion(int version) {
    4153        this.version = version;
     
    5062    }
    5163
     64    /**
     65     * Returns a copy of this primitive data.
     66     * @return a copy of this primitive data
     67     */
    5268    public abstract PrimitiveData makeCopy();
    5369
     
    8298        oos.writeInt(timestamp);
    8399        oos.writeObject(keys);
     100        oos.writeShort(flags);
    84101        oos.defaultWriteObject();
    85102    }
     
    94111        timestamp = ois.readInt();
    95112        keys = (String[]) ois.readObject();
     113        flags = ois.readShort();
    96114        ois.defaultReadObject();
    97115    }
  • trunk/test/unit/org/openstreetmap/josm/data/osm/NodeDataTest.java

    r10733 r10946  
    22package org.openstreetmap.josm.data.osm;
    33
     4import static org.junit.Assert.assertNull;
     5import static org.junit.Assert.assertTrue;
     6
    47import java.io.ByteArrayInputStream;
    58import java.io.ByteArrayOutputStream;
     9import java.io.IOException;
    610import java.io.ObjectInputStream;
    711import java.io.ObjectOutputStream;
     
    1216
    1317public class NodeDataTest {
     18
     19    private static NodeData serializeUnserialize(NodeData data) throws IOException, ClassNotFoundException {
     20        try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
     21             ObjectOutputStream out = new ObjectOutputStream(bytes)) {
     22            out.writeObject(data);
     23            try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
     24                return (NodeData) in.readObject();
     25            }
     26        }
     27    }
     28
    1429    @Test
    1530    public void testSerializationForDragAndDrop() throws Exception {
     
    1934        data.setVersion(14);
    2035        data.setChangesetId(314159);
    21         final Object readData;
    22         try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    23              ObjectOutputStream out = new ObjectOutputStream(bytes)) {
    24             out.writeObject(data);
    25             try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
    26                 readData = in.readObject();
    27             }
    28         }
     36        final NodeData readData = serializeUnserialize(data);
    2937        Assert.assertEquals(data.toString(), readData.toString());
    3038    }
     39
     40    /**
     41     * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/13395">#13395</a>.
     42     * @throws Exception if an error occurs
     43     */
     44    @Test
     45    public void testTicket13395() throws Exception {
     46        Node n = new Node(1925320646, 1);
     47        n.setCoor(null);
     48        assertNull(n.getCoor());
     49        assertTrue(n.isIncomplete());
     50
     51        NodeData data = n.save();
     52        assertNull(data.getCoor());
     53        assertTrue(data.isIncomplete());
     54
     55        NodeData readData = serializeUnserialize(data);
     56        assertNull(readData.getCoor());
     57        assertTrue(readData.isIncomplete());
     58    }
    3159}
Note: See TracChangeset for help on using the changeset viewer.