Class JNLPClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public class JNLPClassLoader extends URLClassLoader
Classloader that takes it's resources from a JNLP file. If the JNLP file defines extensions, separate classloaders for these will be created automatically. Classes are loaded with the security context when the classloader was created.
  • Field Details

  • Constructor Details

    • JNLPClassLoader

      protected JNLPClassLoader(JNLPFile file, UpdatePolicy policy) throws LaunchException
      Create a new JNLPClassLoader from the specified file.
      Parameters:
      file - the JNLP file
      policy - update policy of loader
      Throws:
      LaunchException - if app can not be loaded
    • JNLPClassLoader

      protected JNLPClassLoader(JNLPFile file, UpdatePolicy policy, String mainName, boolean enableCodeBase) throws LaunchException
      Create a new JNLPClassLoader from the specified file.
      Parameters:
      file - the JNLP file
      policy - the UpdatePolicy for this class loader
      mainName - name of the application's main class
      enableCodeBase - switch whether this classloader can search in codebase or not
      Throws:
      LaunchException - when need to kill an app comes.
  • Method Details

    • isCertUnderestimated

      public static boolean isCertUnderestimated()
    • isStrict

      public boolean isStrict()
    • getInstance

      public static JNLPClassLoader getInstance(JNLPFile file, UpdatePolicy policy, boolean enableCodeBase) throws LaunchException
      Returns a JNLP classloader for the specified JNLP file.
      Parameters:
      file - the file to load classes for
      policy - the update policy to use when downloading resources
      enableCodeBase - true if codebase can be searched (ok for applets,false for apps)
      Returns:
      existing classloader. creates new if none reliable exists
      Throws:
      LaunchException - when launch is doomed
    • getInstance

      public static JNLPClassLoader getInstance(JNLPFile file, UpdatePolicy policy, String mainName, boolean enableCodeBase) throws LaunchException
      Returns a JNLP classloader for the specified JNLP file.
      Parameters:
      file - the file to load classes for
      policy - the update policy to use when downloading resources
      mainName - Overrides the main class name of the application
      enableCodeBase - ue if codebase can be searched (ok for applets,false for apps)
      Returns:
      existing classloader. creates new if none reliable exists
      Throws:
      LaunchException - when launch is doomed
    • getInstance

      public static JNLPClassLoader getInstance(URL location, String uniqueKey, Version version, ParserSettings settings, UpdatePolicy policy, String mainName, boolean enableCodeBase) throws IOException, ParseException, LaunchException
      Returns a JNLP classloader for the JNLP file at the specified location.
      Parameters:
      location - the file's location
      uniqueKey - key to manage applets/applications in shared vm
      version - the file's version
      settings - settings of parser
      policy - the update policy to use when downloading resources
      mainName - Overrides the main class name of the application
      enableCodeBase - whether to enable codebase search or not
      Returns:
      classlaoder of this appp
      Throws:
      IOException - when IO fails
      ParseException - when parsing fails
      LaunchException - when launch is doomed
    • checkForAttributeInJars

      public String checkForAttributeInJars(List<JARDesc> jars, Attributes.Name name)
      * Checks for the jar that contains the attribute.
      Parameters:
      jars - Jars that are checked to see if they contain the main class
      name - attribute to be found
      Returns:
      value of attribute if found
    • getManifestAttribute

      public String getManifestAttribute(URL location, Attributes.Name attribute)
      Gets the name of the main method if specified in the manifest
      Parameters:
      location - The JAR location
      attribute - name of the attribute to find
      Returns:
      the attribute value, null if there isn't one of if there was an error
    • hasMainJar

      public boolean hasMainJar()
      Returns:
      true if this loader has the main jar
    • setRunInSandbox

      public void setRunInSandbox() throws LaunchException
      Throws:
      LaunchException
    • userPromptedForSandbox

      public boolean userPromptedForSandbox()
    • enableCodeBase

      public void enableCodeBase()
      Add applet's codebase URL. This allows compatibility with applets that load resources from their codebase instead of through JARs, but can slow down resource loading. Resources loaded from the codebase are not cached.
    • setApplication

      public void setApplication(ApplicationInstance app)
      Sets the JNLP app this group is for; can only be called once.
      Parameters:
      app - application to be ser to this group
    • getApplication

      public ApplicationInstance getApplication()
      Returns:
      the JNLP app for this classloader
    • getJNLPFile

      public JNLPFile getJNLPFile()
      Returns:
      the JNLP file the classloader was created from.
    • getPermissions

      protected PermissionCollection getPermissions(CodeSource cs)
      Returns the permissions for the CodeSource.
      Overrides:
      getPermissions in class URLClassLoader
    • addPermission

      protected void addPermission(Permission p)
    • fillInPartJars

      protected void fillInPartJars(List<JARDesc> jars)
      Adds to the specified list of JARS any other JARs that need to be loaded at the same time as the JARs specified (ie, are in the same part).
      Parameters:
      jars - jar archives to be added
    • activateJars

      protected void activateJars(List<JARDesc> jars)
      Ensures that the list of jars have all been transferred, and makes them available to the classloader. If a jar contains native code, the libraries will be extracted and placed in the path.
      Parameters:
      jars - the list of jars to load
    • findLibrary

      protected String findLibrary(String lib)
      Return the absolute path to the native library.
      Overrides:
      findLibrary in class ClassLoader
    • findLibraryExt

      protected String findLibraryExt(String lib)
      Try to find the library path from another peer classloader.
      Parameters:
      lib - library to be found
      Returns:
      location of library
    • findLoadedClassAll

      protected Class<?> findLoadedClassAll(String name)
      Find the loaded class in this loader or any of its extension loaders.
      Parameters:
      name - name of class
      Returns:
      the class found by name
    • loadClass

      public Class<?> loadClass(String name) throws ClassNotFoundException
      Find a JAR in the shared 'extension' classloaders, this classloader, or one of the classloaders for the JNLP file's extensions. This method used to be qualified "synchronized." This was done solely for the purpose of ensuring only one thread entered the method at a time. This was not strictly necessary - ensuring that all affected fields are thread-safe is sufficient. Locking on the JNLPClassLoader instance when this method is called can result in deadlock if another thread is dealing with the CodebaseClassLoader at the same time. This solution is very heavy-handed as the instance lock is not truly required, and taking the lock on the classloader instance when not needed is not in general a good idea because it can and will lead to deadlock when multithreaded classloading is in effect. The solution is to keep the fields thread safe on their own. This is accomplished by wrapping them in Collections.synchronized* to provide atomic add/remove operations, and synchronizing on them when iterating or performing multiple mutations. See bug report RH976833. On some systems this bug will manifest itself as deadlock on every webpage with more than one Java applet, potentially also causing the browser process to hang. More information in the mailing list archives: http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2013-September/024536.html Affected fields: available, classpaths, jarIndexes, jarEntries, jarLocationSecurityMap
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • findClass

      protected Class<?> findClass(String name) throws ClassNotFoundException
      Find the class in this loader or any of its extension loaders.
      Overrides:
      findClass in class URLClassLoader
      Throws:
      ClassNotFoundException
    • findResource

      public URL findResource(String name)
      Finds the resource in this, the parent, or the extension class loaders.
      Overrides:
      findResource in class URLClassLoader
      Returns:
      a URL for the resource, or null if the resource could not be found.
    • findResources

      public Enumeration<URL> findResources(String name) throws IOException
      Find the resources in this, the parent, or the extension class loaders. Load lazy resources if not found in current resources.
      Overrides:
      findResources in class URLClassLoader
      Throws:
      IOException
    • resourceAvailableLocally

      public boolean resourceAvailableLocally(String s)
      Returns if the specified resource is available locally from a cached jar
      Parameters:
      s - The name of the resource
      Returns:
      Whether or not the resource is available locally
    • addAvailable

      protected void addAvailable()
      Adds whatever resources have already been downloaded in the background.
    • addNextResource

      protected JNLPClassLoader addNextResource() throws LaunchException
      Adds the next unused resource to the classloader. That resource and all those in the same part will be downloaded and added to the classloader before returning. If there are no more resources to add, the method returns immediately.
      Returns:
      the classloader that resources were added to, or null
      Throws:
      LaunchException - Thrown if the signed JNLP file, within the main jar, fails to be verified or does not match
    • getExtensionName

      @Deprecated public String getExtensionName()
      Deprecated.
      Returns:
      title if available. Substitutions if not.
    • getExtensionHREF

      @Deprecated public String getExtensionHREF()
      Deprecated.
      Returns:
      location if jnlp
    • getSigning

      public boolean getSigning()
    • getSigningState

      public JNLPClassLoader.SigningState getSigningState()
    • getSecurity

      protected SecurityDesc getSecurity()
    • getCodeSourceSecurity

      protected SecurityDesc getCodeSourceSecurity(URL source)
      Returns the security descriptor for given code source URL
      Parameters:
      source - the origin (remote) url of the code
      Returns:
      The SecurityDescriptor for that source
    • decrementLoaderUseCount

      public void decrementLoaderUseCount()
      Decrements loader use count by 1 If count reaches 0, loader is removed from list of available loaders
      Throws:
      SecurityException - if caller is not trusted
    • getAccessControlContextForClassLoading

      public AccessControlContext getAccessControlContextForClassLoading()
      Returns an appropriate AccessControlContext for loading classes in the running instance. The default context during class-loading only allows connection to codebase. However applets are allowed to load jars from arbitrary locations and the codebase only access falls short if a class from one location needs a class from another. Given protected access since CodeBaseClassloader uses this function too.
      Returns:
      The appropriate AccessControlContext for loading classes for this instance
    • getMainClass

      public String getMainClass()