Changeset 14201 in josm for trunk


Ignore:
Timestamp:
2018-08-29T19:40:53+02:00 (12 months ago)
Author:
Don-vip
Message:

spotbugs - fix various issues found with Eclipse plugin

Location:
trunk
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/BuildProjectionDefinitions.java

    r13708 r14201  
    88import java.nio.charset.StandardCharsets;
    99import java.util.Arrays;
     10import java.util.Collections;
    1011import java.util.LinkedHashMap;
    1112import java.util.List;
     
    7475
    7576    static List<String> initList(String baseDir, String ext) {
    76         return Arrays.asList(new File(baseDir + File.separator + PROJ_DIR)
    77                 .list((dir, name) -> !name.contains(".") || name.toLowerCase(Locale.ENGLISH).endsWith(ext)));
     77        String[] result = new File(baseDir + File.separator + PROJ_DIR)
     78                .list((dir, name) -> !name.contains(".") || name.toLowerCase(Locale.ENGLISH).endsWith(ext));
     79        return result != null ? Arrays.asList(result) : Collections.emptyList();
    7880    }
    7981
  • trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java

    r14153 r14201  
    320320                }
    321321
     322                Pattern urlPattern = Pattern.compile(".*(https?://.*)");
    322323                for (File urlFile: urlFiles) {
    323324                    try (BufferedReader reader = Files.newBufferedReader(urlFile.toPath(), StandardCharsets.UTF_8)) {
    324325                        String line;
    325326                        while ((line = reader.readLine()) != null) {
    326                             Matcher m = Pattern.compile(".*(https?://.*)").matcher(line);
     327                            Matcher m = urlPattern.matcher(line);
    327328                            if (m.matches()) {
    328329                                String url = m.group(1);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r14128 r14201  
    425425     * Add a new map paint style.
    426426     * @param entry map paint style
    427      * @return loaded style source, or {@code null}
     427     * @return loaded style source
    428428     */
    429429    public static StyleSource addStyle(SourceEntry entry) {
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r14153 r14201  
    653653        Collection<String> parameters = new ArrayList<>();
    654654        NodeList paramNl = parametersEl.getElementsByTagName("param");
    655         for (int i = 0; i < paramNl.getLength(); i++) {
     655        int length = paramNl.getLength();
     656        for (int i = 0; i < length; i++) {
    656657            Element paramEl = (Element) paramNl.item(i);
    657658            parameters.add(paramEl.getTextContent());
  • trunk/test/performance/org/openstreetmap/josm/data/osm/KeyValuePerformanceTest.java

    r14093 r14201  
    157157     */
    158158    @Test
     159    @SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT")
    159160    public void testKeyValueGet() {
    160161        for (double tagNodeRatio : TAG_NODE_RATIOS) {
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/PluginDownloadTaskTest.java

    r14149 r14201  
    99import java.io.FileInputStream;
    1010import java.io.FileOutputStream;
     11import java.nio.charset.StandardCharsets;
    1112import java.util.Collections;
    1213
     
    3536    @Rule
    3637    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    37     public JOSMTestRules test = new JOSMTestRules().https().assumeRevision(
     38    public JOSMTestRules testRule = new JOSMTestRules().https().assumeRevision(
    3839        "Revision: 8000\n"
    3940    ).preferences();
     
    6869        // put existing "plugin file" in place
    6970        pluginFile.getParentFile().mkdirs();
    70         final byte[] existingPluginContents = "Existing plugin contents 123".getBytes();
     71        final byte[] existingPluginContents = "Existing plugin contents 123".getBytes(StandardCharsets.UTF_8);
    7172        try (FileOutputStream existingPluginOutputStream = new FileOutputStream(pluginFile)) {
    7273            existingPluginOutputStream.write(existingPluginContents);
     
    111112
    112113        pluginFile.getParentFile().mkdirs();
    113         final byte[] existingPluginContents = "Existing plugin contents 123".getBytes();
     114        final byte[] existingPluginContents = "Existing plugin contents 123".getBytes(StandardCharsets.UTF_8);
    114115        try (FileOutputStream existingPluginOutputStream = new FileOutputStream(pluginFile)) {
    115116            existingPluginOutputStream.write(existingPluginContents);
  • trunk/test/unit/org/openstreetmap/josm/data/UserIdentityManagerTest.java

    r12849 r14201  
    102102     */
    103103    @Test(expected = IllegalArgumentException.class)
     104    @SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS")
    104105    public void testSetPartiallyIdentifiedNull() {
    105106        UserIdentityManager.getInstance().setPartiallyIdentified(null);
     
    149150     */
    150151    @Test(expected = IllegalArgumentException.class)
     152    @SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS")
    151153    public void testSetFullyIdentifiedNullName() {
    152154        UserIdentityManager.getInstance().setFullyIdentified(null, newUserInfo());
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java

    r13779 r14201  
    545545        assertArrayEquals("cached dummy".getBytes(StandardCharsets.UTF_8), listener.data);
    546546        assertTrue(testStart + expires <= listener.attributes.getExpirationTime());
    547         listener = submitJob(job, false);
     547        submitJob(job, false);
    548548        tileServer.verify(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test"))); // no more requests were made
    549549    }
  • trunk/test/unit/org/openstreetmap/josm/data/coor/LatLonTest.java

    r13079 r14201  
    77
    88import java.text.DecimalFormat;
     9import java.util.Arrays;
     10import java.util.List;
    911
    1012import org.junit.Rule;
     
    3436     * Lat/Lon sample values for unit tests
    3537     */
    36     @SuppressFBWarnings(value = "MS_PKGPROTECT")
    37     public static final double[] SAMPLE_VALUES = new double[]{
     38    public static final List<Double> SAMPLE_VALUES = Arrays.asList(
    3839            // CHECKSTYLE.OFF: SingleSpaceSeparator
    3940            -180.0, -179.9, -179.6, -179.5, -179.4, -179.1, -179.0, -100.0, -99.9, -10.0, -9.9, -1.0, -0.1,
     
    4445            100.12, 100.123, 100.1234, 100.12345, 100.123456, 100.1234567
    4546            // CHECKSTYLE.ON: SingleSpaceSeparator
    46            };
     47            );
    4748
    4849    /**
  • trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetCacheTest.java

    r14166 r14201  
    6060        protected final void await() {
    6161            try {
    62                 latch.await(2, TimeUnit.SECONDS);
     62                Logging.trace(Boolean.toString(latch.await(2, TimeUnit.SECONDS)));
    6363            } catch (InterruptedException e) {
    6464                Logging.error(e);
  • trunk/test/unit/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolutionUtilTest.java

    r11614 r14201  
    55import static org.junit.Assert.assertFalse;
    66import static org.junit.Assert.assertNull;
    7 import static org.junit.Assert.assertSame;
    87import static org.junit.Assert.assertTrue;
    98
     
    8281        tc.add(otherSource); // other source should prevent resolution
    8382        TagConflictResolutionUtil.applyAutomaticTagConflictResolution(tc);
    84         assertSame(18, tc.getValues("source").size());
     83        assertEquals(18, tc.getValues("source").size());
    8584        tc.remove(otherSource);
    8685        TagConflictResolutionUtil.applyAutomaticTagConflictResolution(tc);
     
    373372        public void testGroupChoices() {
    374373            Collection<AutomaticChoiceGroup> groups = AutomaticChoiceGroup.groupChoices(Arrays.asList(choiceKey1Group1, choiceKey1Group2));
    375             assertSame(2, groups.size());
     374            assertEquals(2, groups.size());
    376375
    377376            groups = AutomaticChoiceGroup.groupChoices(Arrays.asList(
    378377                choiceKey1Group1, choiceKey1Group2, choiceKey2Group1, choiceKey2Group2, choiceEmpty));
    379             assertSame(5, groups.size());
     378            assertEquals(5, groups.size());
    380379
    381380            groups = AutomaticChoiceGroup.groupChoices(Arrays.asList(choiceKey1Group1, choiceKey1Group1bis));
    382             assertSame(1, groups.size());
     381            assertEquals(1, groups.size());
    383382            AutomaticChoiceGroup group1 = groups.iterator().next();
    384383            assertEquals(group1.key, choiceKey1Group1.key);
     
    389388                choiceKey1Group1, choiceKey1Group1bis, choiceKey1Group2, choiceKey1Group2bis,
    390389                choiceKey2Group1, choiceKey2Group1bis, choiceKey2Group2, choiceKey2Group2bis));
    391             assertSame(4, groups.size());
     390            assertEquals(4, groups.size());
    392391            for (AutomaticChoiceGroup group: groups) {
    393392                for (AutomaticChoice choice: group.choices) {
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/MinimapDialogTest.java

    r14149 r14201  
    1616import java.util.Arrays;
    1717import java.util.Map;
     18import java.util.Objects;
    1819import java.util.concurrent.Callable;
    1920import java.util.regex.Matcher;
     
    113114                        // sources should all come before any separators
    114115                        break;
    115                     } else if (((JMenuItem) c).getText() == label) {
     116                    } else if (Objects.equals(((JMenuItem) c).getText(), label)) {
    116117                        ((JMenuItem) c).doClick();
    117118                        return;
     
    127128    }
    128129
    129     protected MinimapDialog minimap;
    130     protected SlippyMapBBoxChooser slippyMap;
    131     protected SourceButton sourceButton;
    132     protected Callable<Boolean> slippyMapTasksFinished;
    133 
    134     protected static BufferedImage paintedSlippyMap;
     130    private MinimapDialog minimap;
     131    private SlippyMapBBoxChooser slippyMap;
     132    private SourceButton sourceButton;
     133    private Callable<Boolean> slippyMapTasksFinished;
     134
     135    private static BufferedImage paintedSlippyMap;
    135136
    136137    protected void setUpMiniMap() {
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/AutosaveTaskTest.java

    r14138 r14201  
    1212import java.io.IOException;
    1313import java.nio.charset.StandardCharsets;
     14import java.nio.file.DirectoryStream;
    1415import java.nio.file.Files;
    1516import java.nio.file.Path;
     
    115116        }
    116117        // cleanup
    117         for (Path entry : Files.newDirectoryStream(task.getAutosaveDir(), "*.{osm,pid}")) {
    118             Files.delete(entry);
     118        try (DirectoryStream<Path> stream = Files.newDirectoryStream(task.getAutosaveDir(), "*.{osm,pid}")) {
     119            for (Path entry : stream) {
     120                Files.delete(entry);
     121            }
    119122        }
    120123    }
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTestIT.java

    r13655 r14201  
    66
    77import java.util.Collection;
    8 import java.util.Collections;
    98import java.util.HashMap;
    109import java.util.Map;
     
    8483                    }
    8584                }
    86                 if (style != null) {
    87                     System.out.println(style.isValid() ? " => OK" : " => KO");
    88                     Collection<Throwable> errors = style.getErrors();
    89                     Collection<String> warnings = style.getWarnings();
    90                     if (!errors.isEmpty()) {
    91                         allErrors.put(source.url, errors);
    92                     }
    93                     if (!warnings.isEmpty()) {
    94                         allWarnings.put(source.url, warnings);
    95                     }
    96                 } else {
    97                     allWarnings.put(source.url, Collections.singleton("MapPaintStyles.addStyle() returned null"));
     85                System.out.println(style.isValid() ? " => OK" : " => KO");
     86                Collection<Throwable> errors = style.getErrors();
     87                Collection<String> warnings = style.getWarnings();
     88                if (!errors.isEmpty()) {
     89                    allErrors.put(source.url, errors);
     90                }
     91                if (!warnings.isEmpty()) {
     92                    allWarnings.put(source.url, warnings);
    9893                }
    9994            }
  • trunk/test/unit/org/openstreetmap/josm/io/OsmChangesetContentParserTest.java

    r14047 r14201  
    5353     */
    5454    @Test
     55    @SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_NONVIRTUAL")
    5556    public void test_Constructor() {
    5657
    5758        // should be OK
    58         new OsmChangesetContentParser(new ByteArrayInputStream("".getBytes()));
     59        new OsmChangesetContentParser(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)));
    5960
    6061        shouldFail(() -> {
  • trunk/test/unit/org/openstreetmap/josm/io/OsmJsonReaderTest.java

    r14086 r14201  
    99import java.io.InputStream;
    1010import java.nio.charset.StandardCharsets;
    11 import java.text.SimpleDateFormat;
    1211import java.util.Iterator;
    1312
     
    3938    public JOSMTestRules test = new JOSMTestRules();
    4039
    41     private static final SimpleDateFormat iso8601 = DateUtils.newIsoDateTimeFormat();
    42 
    4340    /**
    4441     * Setup test
     
    4643    @BeforeClass
    4744    public static void setUp() {
    48         iso8601.setTimeZone(DateUtils.UTC);
     45        DateUtils.newIsoDateTimeFormat().setTimeZone(DateUtils.UTC);
    4946    }
    5047
     
    122119        assertEquals(1, n.getUniqueId());
    123120        assertEquals(new LatLon(2.0, -3.0), n.getCoor());
    124         assertEquals("2018-01-01T00:00:00Z", iso8601.format(n.getTimestamp()));
     121        assertEquals("2018-01-01T00:00:00Z", DateUtils.newIsoDateTimeFormat().format(n.getTimestamp()));
    125122        assertEquals(4, n.getVersion());
    126123        assertEquals(5, n.getChangesetId());
  • trunk/test/unit/org/openstreetmap/josm/io/OsmWriterTest.java

    r13559 r14201  
    77import java.io.ByteArrayOutputStream;
    88import java.io.IOException;
     9import java.io.OutputStreamWriter;
    910import java.io.PrintWriter;
     11import java.nio.charset.StandardCharsets;
    1012import java.util.ArrayList;
    1113import java.util.Arrays;
     
    1517import org.junit.Test;
    1618import org.openstreetmap.josm.data.osm.DownloadPolicy;
     19import org.openstreetmap.josm.data.osm.NodeData;
    1720import org.openstreetmap.josm.data.osm.UploadPolicy;
    18 import org.openstreetmap.josm.data.osm.NodeData;
    1921
    2022/**
     
    6062    private static void doTestHeader(DownloadPolicy download, UploadPolicy upload, String expected) throws IOException {
    6163        ByteArrayOutputStream baos = new ByteArrayOutputStream();
    62         try (PrintWriter out = new PrintWriter(baos);
     64        try (PrintWriter out = new PrintWriter(new OutputStreamWriter(baos, StandardCharsets.UTF_8));
    6365             OsmWriter writer = OsmWriterFactory.createOsmWriter(out, true, OsmWriter.DEFAULT_API_VERSION)) {
    6466            writer.header(download, upload);
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r14168 r14201  
    4646    private String httpsBase;
    4747
     48    private static class PlatformHookWindowsMock extends MockUp<PlatformHookWindows> {
     49        @Mock
     50        public boolean setupHttpsCertificate(String entryAlias, TrustedCertificateEntry trustedCert) {
     51            return true;
     52        }
     53    }
     54
    4855    /**
    4956     * Starts Remote control before testing requests.
     
    5966            // appveyor doesn't like us tinkering with the root keystore, so mock this out
    6067            TestUtils.assumeWorkingJMockit();
    61             new MockUp<PlatformHookWindows>() {
    62                 @Mock
    63                 public boolean setupHttpsCertificate(String entryAlias, TrustedCertificateEntry trustedCert) {
    64                     return true;
    65                 }
    66             };
     68            new PlatformHookWindowsMock();
    6769        }
    6870
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r14153 r14201  
    88import java.io.File;
    99import java.io.IOException;
     10import java.nio.charset.StandardCharsets;
    1011import java.security.GeneralSecurityException;
    1112import java.text.MessageFormat;
     
    360361        MockVersion(final String propertiesString) {
    361362            super.initFromRevisionInfo(
    362                 new ByteArrayInputStream(propertiesString.getBytes())
     363                new ByteArrayInputStream(propertiesString.getBytes(StandardCharsets.UTF_8))
    363364            );
    364365        }
  • trunk/test/unit/org/openstreetmap/josm/testutils/TileSourceRule.java

    r14066 r14201  
    4747     * this cache
    4848     */
    49     public static HashMap<ConstSource, ByteArrayWrapper> constPayloadCache = new HashMap<>();
     49    public static final HashMap<ConstSource, ByteArrayWrapper> constPayloadCache = new HashMap<>();
    5050
    5151    /**
  • trunk/test/unit/org/openstreetmap/josm/testutils/mockers/HelpAwareOptionPaneMocker.java

    r14062 r14201  
    165165                    "Invalid result for HelpAwareOptionPane: %s (in call with options = %s)",
    166166                    retval,
    167                     options
     167                    Arrays.asList(options)
    168168                ));
    169169            }
  • trunk/test/unit/org/openstreetmap/josm/tools/ImageProviderTest.java

    r13823 r14201  
    2222
    2323import com.kitfox.svg.SVGConst;
     24
     25import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2426
    2527/**
     
    8587     */
    8688    @Test
     89    @SuppressFBWarnings(value = "LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE")
    8790    public void testTicket14319() throws IOException {
    8891        LogHandler14319 handler = new LogHandler14319();
Note: See TracChangeset for help on using the changeset viewer.