Ticket #20341: 20341-core-V4.diff

File 20341-core-V4.diff, 8.8 KB (added by Bjoeni, 5 years ago)
  • src/org/openstreetmap/josm/data/gpx/GpxImageEntry.java

     
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    66import java.io.File;
     7import java.io.IOException;
    78import java.util.Date;
    89import java.util.List;
     10import java.util.Locale;
    911import java.util.Objects;
    1012import java.util.function.Consumer;
    1113
     
    1820import org.openstreetmap.josm.tools.Logging;
    1921
    2022import com.drew.imaging.jpeg.JpegMetadataReader;
     23import com.drew.imaging.jpeg.JpegProcessingException;
    2124import com.drew.imaging.png.PngMetadataReader;
     25import com.drew.imaging.png.PngProcessingException;
    2226import com.drew.imaging.tiff.TiffMetadataReader;
     27import com.drew.imaging.tiff.TiffProcessingException;
    2328import com.drew.metadata.Directory;
    2429import com.drew.metadata.Metadata;
    2530import com.drew.metadata.MetadataException;
     
    587592
    588593        try {
    589594            // try to parse metadata according to extension
    590             String ext = fn.substring(fn.lastIndexOf(".") + 1).toLowerCase();
     595            String ext = fn.substring(fn.lastIndexOf('.') + 1).toLowerCase(Locale.US);
    591596            switch (ext) {
    592597            case "jpg":
    593598            case "jpeg":
     
    603608            default:
    604609                throw new NoMetadataReaderWarning(ext);
    605610            }
    606         } catch (Exception topException) {
     611        } catch (JpegProcessingException | TiffProcessingException | PngProcessingException | IOException
     612                | NoMetadataReaderWarning topException) {
    607613            //try other formats (e.g. JPEG file with .png extension)
    608614            try {
    609615                metadata = JpegMetadataReader.readMetadata(file);
    610             } catch (Exception ex1) {
     616            } catch (JpegProcessingException | IOException ex1) {
    611617                try {
    612618                    metadata = TiffMetadataReader.readMetadata(file);
    613                 } catch (Exception ex2) {
     619                } catch (TiffProcessingException | IOException ex2) {
    614620                    try {
    615621                        metadata = PngMetadataReader.readMetadata(file);
    616                     } catch (Exception ex3) {
     622                    } catch (PngProcessingException | IOException ex3) {
    617623
    618624                        Logging.warn(topException);
    619625                        Logging.info(tr("Can''t parse metadata for file \"{0}\". Using last modified date as timestamp.", fn));
  • src/org/openstreetmap/josm/gui/io/importexport/ImageImporter.java

     
    77import java.io.IOException;
    88import java.util.ArrayList;
    99import java.util.Arrays;
     10import java.util.Collections;
    1011import java.util.HashSet;
    1112import java.util.List;
    1213import java.util.Set;
     14import java.util.stream.Collectors;
    1315
    1416import javax.imageio.ImageIO;
    1517
     
    2931    /**
    3032     * The supported image file types on the current system
    3133     */
    32     public static final String[] SUPPORTED_FILE_TYPES = ImageIO.getReaderFileSuffixes();
     34    public static final List<String> SUPPORTED_FILE_TYPES = Collections
     35            .unmodifiableList(Arrays.stream(ImageIO.getReaderFileSuffixes()).sorted().collect(Collectors.toList()));
    3336
    3437    /**
    3538     * The default file filter
  • src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java

     
    242242        }
    243243
    244244        private boolean updateImageEntry(Image img) {
     245            if (img == null) {
     246                synchronized (ImageDisplay.this) {
     247                    errorLoading = true;
     248                    ImageDisplay.this.repaint();
     249                    return false;
     250                }
     251            }
    245252            if (!(entry.getWidth() > 0 && entry.getHeight() > 0)) {
    246253                synchronized (entry) {
    247254                    int width = img.getWidth(this);