Changeset 6282 in josm for trunk


Ignore:
Timestamp:
2013-10-02T00:38:02+02:00 (11 years ago)
Author:
Don-vip
Message:

Sonar/Findbugs - Bad practice - Classloaders should only be created inside doPrivileged block

Location:
trunk/src/org/openstreetmap/josm/plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/Plugin.java

    r5987 r6282  
    99import java.net.URL;
    1010import java.net.URLClassLoader;
     11import java.security.AccessController;
     12import java.security.PrivilegedAction;
    1113import java.util.List;
    1214
     
    142144        File pluginDir = Main.pref.getPluginsDirectory();
    143145        File pluginJar = new File(pluginDir, info.name + ".jar");
    144         URL pluginJarUrl = PluginInformation.fileToURL(pluginJar);
    145         URLClassLoader pluginClassLoader = new URLClassLoader(new URL[] { pluginJarUrl } , Main.class.getClassLoader());
    146         return pluginClassLoader;
     146        final URL pluginJarUrl = PluginInformation.fileToURL(pluginJar);
     147        return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
     148              public ClassLoader run() {
     149                  return new URLClassLoader(new URL[] {pluginJarUrl}, Main.class.getClassLoader());
     150              }
     151        });
    147152    }
    148153}
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r6248 r6282  
    1616import java.net.URL;
    1717import java.net.URLClassLoader;
     18import java.security.AccessController;
     19import java.security.PrivilegedAction;
    1820import java.util.ArrayList;
    1921import java.util.Arrays;
     
    527529
    528530        // create a classloader for all plugins:
    529         URL[] jarUrls = new URL[allPluginLibraries.size()];
    530         jarUrls = allPluginLibraries.toArray(jarUrls);
    531         URLClassLoader pluginClassLoader = new URLClassLoader(jarUrls, Main.class.getClassLoader());
    532         return pluginClassLoader;
     531        final URL[] jarUrls = allPluginLibraries.toArray(new URL[allPluginLibraries.size()]);
     532        return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
     533            public ClassLoader run() {
     534                return new URLClassLoader(jarUrls, Main.class.getClassLoader());
     535            }
     536      });
    533537    }
    534538
Note: See TracChangeset for help on using the changeset viewer.