Ignore:
Timestamp:
2016-11-27T05:16:30+01:00 (7 years ago)
Author:
Don-vip
Message:

findbugs

Location:
trunk/test/unit/org/openstreetmap/josm/data
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/AutosaveTaskTest.java

    r11035 r11324  
    88import static org.junit.Assert.assertTrue;
    99
     10import java.io.BufferedWriter;
    1011import java.io.File;
    11 import java.io.FileWriter;
    12 import java.io.FilenameFilter;
    1312import java.io.IOException;
     13import java.nio.charset.StandardCharsets;
    1414import java.nio.file.Files;
    1515import java.nio.file.Paths;
     
    143143
    144144    private int countFiles() {
    145         return task.getAutosaveDir().toFile().list(new FilenameFilter() {
    146             @Override
    147             public boolean accept(File dir, String name) {
    148                 return name.endsWith(".osm");
    149             }
    150         }).length;
     145        String[] files = task.getAutosaveDir().toFile().list((dir, name) -> name.endsWith(".osm"));
     146        return files != null ? files.length : 0;
    151147    }
    152148
     
    194190    public void testDiscardUnsavedLayersIgnoresCurrentInstance() throws IOException {
    195191        runAutosaveTaskSeveralTimes(1);
    196         try (FileWriter file = new FileWriter(new File(task.getAutosaveDir().toFile(), "any_other_file.osm"))) {
     192        try (BufferedWriter file = Files.newBufferedWriter(
     193                new File(task.getAutosaveDir().toFile(), "any_other_file.osm").toPath(), StandardCharsets.UTF_8)) {
    197194            file.append("");
    198195        }
     
    237234    public void testRecoverLayers() throws Exception {
    238235        runAutosaveTaskSeveralTimes(1);
    239         try (FileWriter file = new FileWriter(new File(task.getAutosaveDir().toFile(), "any_other_file.osm"))) {
     236        try (BufferedWriter file = Files.newBufferedWriter(
     237                new File(task.getAutosaveDir().toFile(), "any_other_file.osm").toPath(), StandardCharsets.UTF_8)) {
    240238            file.append("<?xml version=\"1.0\"?><osm version=\"0.6\"><node id=\"1\" lat=\"1\" lon=\"2\" version=\"1\"/></osm>");
    241239        }
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCacheManagerTest.java

    r10962 r11324  
    4545            File cacheFile = new File("foobar/testUseBigDiskFile_BLOCK_v2.data");
    4646            if (!cacheFile.exists()) {
    47                 cacheFile.createNewFile();
     47                if (!cacheFile.createNewFile()) {
     48                    System.err.println("Unable to create " + cacheFile.getAbsolutePath());
     49                }
    4850            }
    4951            try (FileOutputStream fileOutputStream = new FileOutputStream(cacheFile, false)) {
  • trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetTest.java

    r11121 r11324  
    3131     */
    3232    @Test
     33    @SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS")
    3334    public void testSetKeys() {
    3435        final Changeset cs = new Changeset();
  • trunk/test/unit/org/openstreetmap/josm/data/osm/NodeDataTest.java

    r10946 r11324  
    1515import org.openstreetmap.josm.data.coor.LatLon;
    1616
     17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     18
    1719public class NodeDataTest {
    1820
     21    @SuppressFBWarnings(value = "OBJECT_DESERIALIZATION")
    1922    private static NodeData serializeUnserialize(NodeData data) throws IOException, ClassNotFoundException {
    2023        try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  • trunk/test/unit/org/openstreetmap/josm/data/osm/QuadBucketsTest.java

    r11269 r11324  
    44import java.io.FileInputStream;
    55import java.io.InputStream;
     6import java.security.SecureRandom;
    67import java.util.ArrayList;
    78import java.util.Arrays;
     
    193194
    194195        // force splits in quad buckets
    195         Random random = new Random(31);
     196        Random random = new SecureRandom();
    196197        for (int i = 0; i < NUM_COMPLETE_WAYS; i++) {
    197198            Way w = new Way(wayId++);
     
    213214
    214215        // add some incomplete nodes
    215         List<Node> incompleteNodes = new ArrayList<>();
    216216        for (int i = 0; i < NUM_INCOMPLETE_NODES; i++) {
    217217            Node n = new Node(nodeId++);
    218             incompleteNodes.add(n);
    219218            n.setIncomplete(true);
    220219            ds.addPrimitive(n);
  • trunk/test/unit/org/openstreetmap/josm/data/osm/WayDataTest.java

    r10733 r11324  
    1111import org.junit.Test;
    1212
     13import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     14
    1315public class WayDataTest {
     16
    1417    @Test
     18    @SuppressFBWarnings(value = "OBJECT_DESERIALIZATION")
    1519    public void testSerializationForDragAndDrop() throws Exception {
    1620        final WayData data = new WayData();
  • trunk/test/unit/org/openstreetmap/josm/data/projection/EllipsoidTest.java

    r10758 r11324  
    22package org.openstreetmap.josm.data.projection;
    33
     4import java.security.SecureRandom;
    45import java.util.Random;
    56
     
    2021    @Test
    2122    public void testLatLon2Cart2LatLon() {
    22         Random r = new Random(System.currentTimeMillis());
     23        Random r = new SecureRandom();
    2324        double maxErrLat = 0, maxErrLon = 0;
    2425        Ellipsoid ellips = Ellipsoid.WGS84;
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java

    r10758 r11324  
    66import java.io.File;
    77import java.io.FileInputStream;
    8 import java.io.FileNotFoundException;
    98import java.io.FileOutputStream;
    109import java.io.IOException;
     
    1413import java.io.OutputStreamWriter;
    1514import java.nio.charset.StandardCharsets;
     15import java.security.SecureRandom;
    1616import java.util.ArrayList;
    1717import java.util.Arrays;
     
    3838import org.openstreetmap.josm.tools.Pair;
    3939import org.openstreetmap.josm.tools.Utils;
     40
     41import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    4042
    4143/**
     
    7274    }
    7375
    74     static Random rand = new Random();
    75 
    76     public static void main(String[] args) throws FileNotFoundException, IOException {
     76    static Random rand = new SecureRandom();
     77
     78    /**
     79     * Program entry point.
     80     * @param args no argument is expected
     81     * @throws IOException in case of I/O error
     82     */
     83    public static void main(String[] args) throws IOException {
    7784        Collection<RefEntry> refs = readData();
    7885        refs = updateData(refs);
     
    200207
    201208    /**
    202      * Run external cs2cs command from the PROJ.4 library to convert lat/lon to
    203      * east/north value.
     209     * Run external cs2cs command from the PROJ.4 library to convert lat/lon to east/north value.
    204210     * @param def the proj.4 projection definition string
    205211     * @param ll the LatLon
    206212     * @return projected EastNorth or null in case of error
    207213     */
     214    @SuppressFBWarnings(value = "COMMAND_INJECTION")
    208215    private static EastNorth latlon2eastNorthProj4(String def, LatLon ll) {
    209216        List<String> args = new ArrayList<>();
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java

    r10758 r11324  
    1212import java.io.OutputStreamWriter;
    1313import java.nio.charset.StandardCharsets;
     14import java.security.SecureRandom;
    1415import java.util.ArrayList;
    1516import java.util.HashMap;
     
    8687        }
    8788
    88         Random rand = new Random();
     89        Random rand = new SecureRandom();
    8990        try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
    9091                new FileOutputStream(PROJECTION_DATA_FILE), StandardCharsets.UTF_8))) {
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionTest.java

    r10758 r11324  
    22package org.openstreetmap.josm.data.projection;
    33
     4import java.security.SecureRandom;
    45import java.util.Arrays;
    56import java.util.Collection;
     
    1819public class ProjectionTest {
    1920
    20     private static Random rand = new Random(System.currentTimeMillis());
     21    private static Random rand = new SecureRandom();
    2122
    2223    boolean error;
Note: See TracChangeset for help on using the changeset viewer.