Changeset 17553 in josm


Ignore:
Timestamp:
2021-03-07T14:44:14+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #20341 - fix Jenkins warnings and NPE caused by malformed images (patch by Bjoeni)

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/gpx/GpxImageEntry.java

    r17548 r17553  
    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;
     
    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;
     
    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":
     
    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) {
    617 
     622                    } catch (PngProcessingException | IOException ex3) {
    618623                        Logging.warn(topException);
    619624                        Logging.info(tr("Can''t parse metadata for file \"{0}\". Using last modified date as timestamp.", fn));
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/ImageImporter.java

    r17548 r17553  
    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;
     
    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    /**
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java

    r17548 r17553  
    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) {
Note: See TracChangeset for help on using the changeset viewer.