Changeset 15588 in josm for trunk/src/org


Ignore:
Timestamp:
2019-12-13T22:12:24+01:00 (5 years ago)
Author:
Don-vip
Message:

tools update: checkstyle 8.27, pmd 6.20, spotbugs 3.1.12

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r15521 r15588  
    279279            SelectionEventManager.getInstance().removeSelectionListener(selectionChangeAdapter);
    280280        }
    281         MainApplication.getToolbar().unregister(this);
     281        if (MainApplication.getToolbar() != null) {
     282            MainApplication.getToolbar().unregister(this);
     283        }
    282284    }
    283285
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r15586 r15588  
    778778            return Stream.empty();
    779779        }
    780         final Stream<OsmPrimitive> stream = referrers instanceof OsmPrimitive
     780        final Stream<OsmPrimitive> stream = referrers instanceof OsmPrimitive // NOPMD
    781781                ? Stream.of((OsmPrimitive) referrers)
    782782                : Arrays.stream((OsmPrimitive[]) referrers);
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r15485 r15588  
    108108     */
    109109    @SuppressWarnings("unchecked")
    110     private static final Class<Test>[] CORE_TEST_CLASSES = new Class[] {
     110    private static final Class<Test>[] CORE_TEST_CLASSES = new Class[] {// NOPMD
    111111        /* FIXME - unique error numbers for tests aren't properly unique - ignoring will not work as expected */
    112112        DuplicateNode.class, // ID    1 ..   99
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r15586 r15588  
    391391            final MapCSSStyleSource source = new MapCSSStyleSource("");
    392392            final MapCSSParser preprocessor = new MapCSSParser(css, MapCSSParser.LexicalState.PREPROCESSOR);
    393             final StringReader mapcss = new StringReader(preprocessor.pp_root(source));
    394             final MapCSSParser parser = new MapCSSParser(mapcss, MapCSSParser.LexicalState.DEFAULT);
    395             parser.sheet(source);
     393            try (StringReader mapcss = new StringReader(preprocessor.pp_root(source))) {
     394                new MapCSSParser(mapcss, MapCSSParser.LexicalState.DEFAULT).sheet(source);
     395            }
    396396            // Ignore "meta" rule(s) from external rules of JOSM wiki
    397397            source.removeMetaRules();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r15492 r15588  
    634634            p.add(new JScrollPane(txtSource), GBC.std().fill());
    635635
    636             try {
    637                 InputStream is = s.getSourceInputStream();
    638                 try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
    639                     String line;
    640                     while ((line = reader.readLine()) != null) {
    641                         txtSource.append(line + '\n');
    642                     }
    643                 } finally {
    644                     s.closeSourceInputStream(is);
    645                 }
     636            try (BufferedReader reader = new BufferedReader(new InputStreamReader(s.getSourceInputStream(), StandardCharsets.UTF_8))) {
     637                reader.lines().forEach(line -> txtSource.append(line + '\n'));
    646638            } catch (IOException ex) {
    647639                Logging.error(ex);
  • trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java

    r14624 r15588  
    689689                String fragmentWithReplacedVars = evalVars(outputWriter.toString());
    690690
    691                 CharArrayReader reader = new CharArrayReader(fragmentWithReplacedVars.toCharArray());
    692                 tmpPref.fromXML(reader);
     691                try (CharArrayReader reader = new CharArrayReader(fragmentWithReplacedVars.toCharArray())) {
     692                    tmpPref.fromXML(reader);
     693                }
    693694            } catch (TransformerException | XMLStreamException | IOException ex) {
    694695                PreferencesUtils.log(ex, "Error: can not read XML fragment:");
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/GeoJSONImporter.java

    r15427 r15588  
    7171    public DataSet parseDataSet(final String source) throws IOException, IllegalDataException {
    7272        try (CachedFile cf = new CachedFile(source)) {
    73             InputStream fileInputStream = Compression.getUncompressedFileInputStream(cf.getFile());
     73            InputStream fileInputStream = Compression.getUncompressedFileInputStream(cf.getFile()); // NOPMD
    7474            return GeoJSONReader.parseDataSet(fileInputStream, NullProgressMonitor.INSTANCE);
    7575        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r15289 r15588  
    433433                    // evaluate @media { ... } blocks
    434434                    MapCSSParser preprocessor = new MapCSSParser(reader, MapCSSParser.LexicalState.PREPROCESSOR);
    435                     String mapcss = preprocessor.pp_root(this);
    436435
    437436                    // do the actual mapcss parsing
    438                     Reader in2 = new StringReader(mapcss);
    439                     MapCSSParser parser = new MapCSSParser(in2, MapCSSParser.LexicalState.DEFAULT);
    440                     parser.sheet(this);
     437                    try (Reader in2 = new StringReader(preprocessor.pp_root(this))) {
     438                        new MapCSSParser(in2, MapCSSParser.LexicalState.DEFAULT).sheet(this);
     439                    }
    441440
    442441                    loadMeta();
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r15447 r15588  
    218218        CheckParameterUtil.ensureThat(daysClosed >= -1, "Requested note limit is less than -1.");
    219219        String url = "notes?limit=" + noteLimit + "&closed=" + daysClosed + "&bbox=" + lon1 + ',' + lat1 + ',' + lon2 + ',' + lat2;
    220         try {
    221             InputStream is = getInputStream(url, progressMonitor.createSubTaskMonitor(1, false));
    222             NoteReader reader = new NoteReader(is);
    223             final List<Note> notes = reader.parse();
     220        try (InputStream is = getInputStream(url, progressMonitor.createSubTaskMonitor(1, false))) {
     221            final List<Note> notes = new NoteReader(is).parse();
    224222            if (notes.size() == noteLimit) {
    225223                throw new MoreNotesException(notes, noteLimit);
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r15416 r15588  
    347347        Pair<String, InputStream> res = null;
    348348        try {
    349             ZipFile zipFile = new ZipFile(file, StandardCharsets.UTF_8);
     349            ZipFile zipFile = new ZipFile(file, StandardCharsets.UTF_8); // NOPMD
    350350            ZipEntry resentry = null;
    351351            Enumeration<? extends ZipEntry> entries = zipFile.entries();
     
    358358            }
    359359            if (resentry != null) {
    360                 InputStream is = zipFile.getInputStream(resentry);
     360                InputStream is = zipFile.getInputStream(resentry); // NOPMD
    361361                res = Pair.create(resentry.getName(), is);
    362362            } else {
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r14979 r15588  
    177177    public static InputStream getUncompressedFileInputStream(File file) throws IOException {
    178178        try {
    179             InputStream in = Files.newInputStream(file.toPath());
     179            InputStream in = Files.newInputStream(file.toPath()); // NOPMD
    180180            try {
    181181                return byExtension(file.getName()).getUncompressedInputStream(in);
     
    221221     */
    222222    public static OutputStream getCompressedFileOutputStream(File file) throws IOException {
    223         OutputStream out = Files.newOutputStream(file.toPath());
     223        OutputStream out = Files.newOutputStream(file.toPath()); // NOPMD
    224224        try {
    225225            return byExtension(file.getName()).getCompressedOutputStream(out);
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r15497 r15588  
    621621     */
    622622    public GpxReader(InputStream source) throws IOException {
    623         Reader utf8stream = UTFInputStreamReader.create(source);
    624         Reader filtered = new InvalidXmlCharacterFilter(utf8stream);
     623        Reader utf8stream = UTFInputStreamReader.create(source); // NOPMD
     624        Reader filtered = new InvalidXmlCharacterFilter(utf8stream); // NOPMD
    625625        this.inputSource = new InputSource(filtered);
    626626    }
  • trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java

    r15247 r15588  
    144144    protected final <T> T doParse(Parser<T> parser, final ProgressMonitor progressMonitor) throws OsmTransferException {
    145145        progressMonitor.beginTask(tr("Contacting Server...", 10));
    146         try {
     146        try { // NOPMD
    147147            return parser.parse();
    148148        } catch (OsmTransferException e) {
     
    211211                return null;
    212212            progressMonitor.subTask(tr("Downloading OSM data..."));
    213             InputStream uncompressedInputStream = compression.getUncompressedInputStream(in);
     213            InputStream uncompressedInputStream = compression.getUncompressedInputStream(in); // NOPMD
    214214            ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(1, false);
    215215            if ("application/json".equals(contentType)) {
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControlHttpServer.java

    r12846 r15588  
    102102            try {
    103103                @SuppressWarnings("resource")
    104                 Socket request = server.accept();
     104                Socket request = server.accept(); // NOPMD
    105105                RequestProcessor.processRequest(request);
    106106            } catch (SocketException e) {
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java

    r15507 r15588  
    66import java.io.IOException;
    77import java.io.InputStreamReader;
    8 import java.io.OutputStream;
    98import java.io.OutputStreamWriter;
    109import java.io.PrintWriter;
     
    2019import java.util.Map;
    2120import java.util.Map.Entry;
     21import java.util.Objects;
    2222import java.util.Optional;
    2323import java.util.StringTokenizer;
     
    8686        super("RemoteControl request processor");
    8787        this.setDaemon(true);
    88         this.request = request;
     88        this.request = Objects.requireNonNull(request);
    8989    }
    9090
     
    9494     */
    9595    public static void processRequest(Socket request) {
    96         RequestProcessor processor = new RequestProcessor(request);
    97         processor.start();
     96        new RequestProcessor(request).start();
    9897    }
    9998
     
    167166    @Override
    168167    public void run() {
    169         Writer out = null;
    170         try {
    171             OutputStream raw = new BufferedOutputStream(request.getOutputStream());
    172             out = new OutputStreamWriter(raw, RESPONSE_CHARSET);
    173             BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), "ASCII"));
     168        Writer out = null; // NOPMD
     169        try { // NOPMD
     170            out = new OutputStreamWriter(new BufferedOutputStream(request.getOutputStream()), RESPONSE_CHARSET);
     171            BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), "ASCII")); // NOPMD
    174172
    175173            String get = in.readLine();
     
    274272                }
    275273            }
    276 
    277274        } catch (IOException ioe) {
    278275            Logging.debug(Logging.getErrorMessage(ioe));
     
    423420            }
    424421
    425             PrintWriter r = new PrintWriter(w);
    426             printJsonInfo(cmd, r, handler);
    427             return w.toString();
     422            try (PrintWriter r = new PrintWriter(w)) {
     423                printJsonInfo(cmd, r, handler);
     424                return w.toString();
     425            }
    428426        } catch (IOException e) {
    429427            Logging.error(e);
  • trunk/src/org/openstreetmap/josm/plugins/PluginListParser.java

    r14189 r15588  
    5959    public List<PluginInformation> parse(InputStream in) throws PluginListParseException {
    6060        List<PluginInformation> ret = new LinkedList<>();
    61         BufferedReader r = null;
    62         try {
    63             r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
     61        try (BufferedReader r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
    6462            String name = null;
    6563            String url = null;
     
    8583                url = x[1];
    8684                manifest = new StringBuilder();
    87 
    8885            }
    8986            addPluginInformation(ret, name, url, manifest.toString());
Note: See TracChangeset for help on using the changeset viewer.