Changeset 10223 in josm for trunk/src


Ignore:
Timestamp:
2016-05-16T04:05:58+02:00 (8 years ago)
Author:
Don-vip
Message:

findbugs: DP_DO_INSIDE_DO_PRIVILEGED + UWF_UNWRITTEN_FIELD + RC_REF_COMPARISON + OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE

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

Legend:

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

    r10212 r10223  
    12031203            structPrototype = klass.getConstructor().newInstance();
    12041204        } catch (ReflectiveOperationException ex) {
    1205             throw new RuntimeException(ex);
     1205            throw new IllegalArgumentException(ex);
    12061206        }
    12071207
     
    12111211                continue;
    12121212            }
    1213             f.setAccessible(true);
     1213            Utils.setObjectsAccessible(f);
    12141214            try {
    12151215                Object fieldValue = f.get(struct);
    12161216                Object defaultFieldValue = f.get(structPrototype);
    1217                 if (fieldValue != null) {
    1218                     if (f.getAnnotation(writeExplicitly.class) != null || !Objects.equals(fieldValue, defaultFieldValue)) {
    1219                         String key = f.getName().replace('_', '-');
    1220                         if (fieldValue instanceof Map) {
    1221                             hash.put(key, mapToJson((Map) fieldValue));
    1222                         } else if (fieldValue instanceof MultiMap) {
    1223                             hash.put(key, multiMapToJson((MultiMap) fieldValue));
    1224                         } else {
    1225                             hash.put(key, fieldValue.toString());
    1226                         }
     1217                if (fieldValue != null && (f.getAnnotation(writeExplicitly.class) != null || !Objects.equals(fieldValue, defaultFieldValue))) {
     1218                    String key = f.getName().replace('_', '-');
     1219                    if (fieldValue instanceof Map) {
     1220                        hash.put(key, mapToJson((Map<?, ?>) fieldValue));
     1221                    } else if (fieldValue instanceof MultiMap) {
     1222                        hash.put(key, multiMapToJson((MultiMap<?, ?>) fieldValue));
     1223                    } else {
     1224                        hash.put(key, fieldValue.toString());
    12271225                    }
    12281226                }
    1229             } catch (IllegalArgumentException | IllegalAccessException ex) {
     1227            } catch (IllegalAccessException ex) {
    12301228                throw new RuntimeException(ex);
    12311229            }
     
    12611259            } catch (NoSuchFieldException ex) {
    12621260                continue;
    1263             } catch (SecurityException ex) {
    1264                 throw new RuntimeException(ex);
    12651261            }
    12661262            if (f.getAnnotation(pref.class) == null) {
    12671263                continue;
    12681264            }
    1269             f.setAccessible(true);
     1265            Utils.setObjectsAccessible(f);
    12701266            if (f.getType() == Boolean.class || f.getType() == boolean.class) {
    12711267                value = Boolean.valueOf(key_value.getValue());
     
    13261322            try {
    13271323                Field field = Toolkit.class.getDeclaredField("resources");
    1328                 field.setAccessible(true);
     1324                Utils.setObjectsAccessible(field);
    13291325                field.set(null, ResourceBundle.getBundle("sun.awt.resources.awt"));
    13301326            } catch (ReflectiveOperationException e) {
  • trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java

    r10212 r10223  
    2525 */
    2626public abstract class PleaseWaitRunnable implements Runnable, CancelListener {
    27     private boolean canceled;
    2827    private boolean ignoreException;
    2928    private final String title;
     
    150149    @Override
    151150    public final void run() {
    152         if (canceled)
    153             return; // since realRun isn't executed, do not call to finish
    154 
    155151        if (EventQueue.isDispatchThread()) {
    156152            new Thread(new Runnable() {
  • trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java

    r9935 r10223  
    9191        if (provider != null) {
    9292            try {
    93                 // TODO
    94                 Field f =  provider.getClass().getDeclaredField("connection");
    95                 f.setAccessible(true);
     93                Field f = provider.getClass().getDeclaredField("connection");
     94                Utils.setObjectsAccessible(f);
    9695                HttpURLConnection con = (HttpURLConnection) f.get(provider);
    9796                if (con != null) {
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmImageView.java

    r10046 r10223  
    1717import org.openstreetmap.josm.Main;
    1818import org.openstreetmap.josm.tools.ImageProvider;
     19import org.openstreetmap.josm.tools.Utils;
    1920
    2021/**
     
    4748        widthField = ImageView.class.getDeclaredField("width");
    4849        heightField = ImageView.class.getDeclaredField("height");
    49         imageField.setAccessible(true);
    50         stateField.setAccessible(true);
    51         widthField.setAccessible(true);
    52         heightField.setAccessible(true);
     50        Utils.setObjectsAccessible(imageField, stateField, widthField, heightField);
    5351    }
    5452
     
    102100            // And update the size params
    103101            Method updateImageSize = ImageView.class.getDeclaredMethod("updateImageSize");
    104             updateImageSize.setAccessible(true);
     102            Utils.setObjectsAccessible(updateImageSize);
    105103            updateImageSize.invoke(this);
    106104        } finally {
     
    130128            } else {
    131129                Method loadImage = ImageView.class.getDeclaredMethod("loadImage");
    132                 loadImage.setAccessible(true);
     130                Utils.setObjectsAccessible(loadImage);
    133131                loadImage.invoke(this);
    134132            }
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r9720 r10223  
    9696     * @throws IOException if any I/O error occurs
    9797     */
    98     @SuppressWarnings("resource")
    9998    public static InputStream getUncompressedFileInputStream(File file) throws IOException {
    100         return byExtension(file.getName()).getUncompressedInputStream(new FileInputStream(file));
     99        FileInputStream in = new FileInputStream(file);
     100        try {
     101            return byExtension(file.getName()).getUncompressedInputStream(in);
     102        } catch (IOException e) {
     103            Utils.close(in);
     104            throw e;
     105        }
    101106    }
    102107
     
    129134     * @throws IOException if any I/O error occurs
    130135     */
    131     @SuppressWarnings("resource")
    132136    public static OutputStream getCompressedFileOutputStream(File file) throws IOException {
    133         return byExtension(file.getName()).getCompressedOutputStream(new FileOutputStream(file));
     137        FileOutputStream out = new FileOutputStream(file);
     138        try {
     139            return byExtension(file.getName()).getCompressedOutputStream(out);
     140        } catch (IOException e) {
     141            Utils.close(out);
     142            throw e;
     143        }
    134144    }
    135145}
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r10212 r10223  
    1111import java.util.Collection;
    1212import java.util.List;
     13import java.util.Objects;
    1314import java.util.regex.Matcher;
    1415import java.util.regex.Pattern;
     
    355356        }
    356357        // Read changeset info if neither upload-changeset nor id are set, or if they are both set to the same value
    357         if (id == uploadChangesetId || (id != null && id.equals(uploadChangesetId))) {
     358        if (Objects.equals(id, uploadChangesetId)) {
    358359            uploadChangeset = new Changeset(id != null ? id.intValue() : 0);
    359360            while (true) {
  • trunk/src/org/openstreetmap/josm/tools/Diff.java

    r10179 r10223  
    386386    }
    387387
    388     private boolean inhibit;
    389 
    390388    /**
    391389     * Adjust inserts/deletes of blank lines to join changes as much as possible.
    392390     */
    393391    private void shift_boundaries() {
    394         if (inhibit)
    395             return;
    396392        filevec[0].shift_boundaries(filevec[1]);
    397393        filevec[1].shift_boundaries(filevec[0]);
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r10066 r10223  
    2626import java.io.InputStreamReader;
    2727import java.io.UnsupportedEncodingException;
     28import java.lang.reflect.AccessibleObject;
    2829import java.net.MalformedURLException;
    2930import java.net.URL;
     
    3435import java.nio.file.Path;
    3536import java.nio.file.StandardCopyOption;
     37import java.security.AccessController;
    3638import java.security.MessageDigest;
    3739import java.security.NoSuchAlgorithmException;
     40import java.security.PrivilegedAction;
    3841import java.text.Bidi;
    3942import java.text.MessageFormat;
     
    15371540    }
    15381541
     1542    /**
     1543     * Sets {@code AccessibleObject}(s) accessible.
     1544     * @param objects objects
     1545     * @see AccessibleObject#setAccessible
     1546     * @since 10223
     1547     */
     1548    public static void setObjectsAccessible(final AccessibleObject ... objects) {
     1549        if (objects != null && objects.length > 0) {
     1550            AccessController.doPrivileged(new PrivilegedAction<Object>() {
     1551                @Override
     1552                public Object run() {
     1553                    for (AccessibleObject o : objects) {
     1554                        o.setAccessible(true);
     1555                    }
     1556                    return null;
     1557                }
     1558            });
     1559        }
     1560    }
    15391561}
Note: See TracChangeset for help on using the changeset viewer.