3 Replies Latest reply: Mar 10, 2011 9:48 AM by 846330 RSS

    Signed Applet get NoClassDefoundError with Trusted-Library: true

    846330
      Hi all,

      I've written a small signed applet that uses to library (one coded by me, but not the other one).
      Without using the "Trusted-Library: true" attribute, all works fine but i get the the warning dialog for the signed and unsigned content.

      When I add (as in http://download.oracle.com/javase/6/docs/technotes/guides/jweb/mixed_code.html) the "Trusted-Library: true" in the three jar files (using "jar ufm jarfile.jar manifestfile") and signed after those jars (with the same certificate) i get the exception NoClassDefFoundException.

      The manifestfile contains "Trusted-Library: true" and a blank line.
      The class not found is in one of the two library.


      What is wrong ?

      Thanks in advance,

      Vincent
        • 1. Re: Signed Applet get NoClassDefoundError with Trusted-Library: true
          baftos
          If you sign all the jars with the same certificate, there should be no need for Trusted-Library = true. All the code and resources must be in the signed jars.
          Trusted-Library = true for a signed jar is supposed to allow you to use unsigned secondary jars (libraries) as well as non-jared classes and resources. But if you do this, you may have to adjust some code in the signed jar, as explained by your link.

          It looks to me that you use Class.forName() or one of the other calls that you would have to modify. Posting a full stack trace may help.
          • 2. Re: Signed Applet get NoClassDefoundError with Trusted-Library: true
            846330
            Hi baftos,

            Thanks for your answer ;-)

            Here is the full stack trace :
            java.lang.RuntimeException: java.lang.NoClassDefFoundError: be/rightink/util/Debug
                 at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3063)
                 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1481)
                 at java.lang.Thread.run(Thread.java:680)
            Caused by: java.lang.NoClassDefFoundError: be/rightink/util/Debug
                 at RequestNew.setDebug(RequestNew.java:208)
                 at RequestNew.<init>(RequestNew.java:203)
                 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
                 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
                 at java.lang.Class.newInstance0(Class.java:355)
                 at java.lang.Class.newInstance(Class.java:308)
                 at sun.plugin2.applet.Plugin2Manager$12.run(Plugin2Manager.java:3005)
                 at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
                 at java.awt.EventQueue.dispatchEvent(EventQueue.java:633)
                 at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
                 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
                 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
                 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
                 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
                 at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
            Caused by: java.lang.ClassNotFoundException: be.rightink.util.Debug
                 at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:194)
                 at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
                 at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
                 at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
                 at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
                 ... 17 more
            Exception : java.lang.RuntimeException: java.lang.NoClassDefFoundError: be/rightink/util/Debug
            Ignored exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: be/rightink/util/Debug
            The line 208 in RequestNew.java is this one :
            Debug.getInstance().setDebugStream(System.out);
            Debug is a class in my external library.

            If i remove this line, it's works :-s

            [Edit] I didn't use code quoted in this :
            Code in a jar file that is to be marked with the Trusted-Library manifest attribute may need to be modified slightly if it uses calls that are class loader dependent, such as >the single parameter version of Class.forName(), Class.getResource(), and Class.getResourceAsStream(), some variants of java.util.ResourceBundle.getBundle(), and any >other methods which operate relative to their immediate caller's defining loader. Changes only need to be made if the requested class or resource might be found in a jar >file which is not a Trusted-Library (and is therefore loaded by the normal Web Start or applet class loader).

            Code in a Trusted-Library can look up the normal loader by invoking Thread.currentThread().getContextClassLoader(). Note, however, that there are uncommon >circumstances in which getContextClassLoader() may return null. For example, this may happen when the garbage collector uses a JRE system thread to invoke the >Object.finalize() method of an unreachable instance.

            If you need to convert class to Class.getResource() or Class.getResourceAsStream() to their ClassLoader equivalents, remember to adjust the string parameter as described >by the documentation for those two methods. If the original resource name began with '/', then it was an absolute name and the leading '/' simply needs to be removed. >Otherwise, determine if the class instance which was the target of the getResource call is in a named package. If it is an array you should first determine the underlying >component type of the array. Invoke Class.getName() on the class or component type instance. If the class name contains any '.' characters, it is in a named package >that will need to be prepended to the original resource name. Determine the package name by removing any characters after, and including, the trailing '.' character. >Next, replace any remaining '.' characters with '/' characters. Finally, add a trailing '/' and append the original resource name string. This new string can now be passed >to the ClassLoader version of the getResource() or getResourceAsStream() methods.
            Also, here is the code of the Debug class (without comments):
            package be.rightink.util;

            import java.io.PrintStream;
            import java.io.OutputStream;

            public class Debug implements Debugable
            {
                 public static Debug debugger = null;
                 
                 protected PrintStream debugStream;
                 
                 public static Debug getInstance()
                 {
                      if( Debug.debugger == null ) {
                           try {
                                Debug.debugger = new Debug();
                           }
                           catch(Exception e) {}
                      }
                      return Debug.debugger;
                 }
                 
                 public Debug() throws Exception
                 {
                      if( Debug.debugger != null )
                           throw new Exception("Use getInstance()");
                      
                      this.debugStream = null;
                 }
                 
                 public void setDebugStream(PrintStream stream)
                 {
                      this.debugStream = stream;
                 }
                 
                 public void setDebugStream(OutputStream stream)
                 {
                      this.debugStream = new PrintStream(stream);
                 }
                 
                 public PrintStream getDebugStream()
                 {
                      return this.debugStream;
                 }
                 
                 public void debug(String message)
                 {
                      if( this.debugStream != null )
                           this.debugStream.println(message);
                 }
            }
            Best regards,

            Vincent

            Edited by: 843327 on 10 mars 2011 06:47

            Edited by: 843327 on 10 mars 2011 06:51
            • 3. Re: Signed Applet get NoClassDefoundError with Trusted-Library: true
              846330
              It seems that the manifest file was not modified for my library. Now it is and i get an other exception. :

              >
              java.lang.reflect.InvocationTargetException
                   at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(DeployAWTUtil.java:116)
                   at sun.plugin2.applet.Plugin2Manager.runOnEDT(Plugin2Manager.java:3467)
                   at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3017)
                   at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1481)
                   at java.lang.Thread.run(Thread.java:680)
              Caused by: java.lang.SecurityException: attempted to open sandboxed jar http://***/riLib.jar as Trusted-Library
                   at com.sun.deploy.security.CPCallbackHandler$ParentElement.checkResource(CPCallbackHandler.java:358)
                   at com.sun.deploy.security.DeployURLClassPath$JarLoader.checkResource(DeployURLClassPath.java:790)
                   at com.sun.deploy.security.DeployURLClassPath$JarLoader.getResource(DeployURLClassPath.java:890)
                   at com.sun.deploy.security.DeployURLClassPath.getResource(DeployURLClassPath.java:231)
                   at sun.plugin2.applet.Plugin2ClassLoader$2.run(Plugin2ClassLoader.java:950)
                   at java.security.AccessController.doPrivileged(Native Method)
                   at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Plugin2ClassLoader.java:939)
                   at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:133)
                   at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
                   at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
                   at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
                   at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
                   at RequestNew.setDebug(RequestNew.java:208)
                   at RequestNew.<init>(RequestNew.java:203)
                   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
                   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                   at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
                   at java.lang.Class.newInstance0(Class.java:355)
                   at java.lang.Class.newInstance(Class.java:308)
                   at sun.plugin2.applet.Plugin2Manager$12.run(Plugin2Manager.java:3005)
                   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
                   at java.awt.EventQueue.dispatchEvent(EventQueue.java:633)
                   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
                   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
                   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
                   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
                   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
                   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
              Exception : java.lang.reflect.InvocationTargetException
              Ignored exception: java.lang.reflect.InvocationTargetException
              >

              *[edit] I don't know what i've changed but it is working no (and it's not a cache problem, i always clean it)*

              Thanks,

              Vincent

              Edited by: 843327 on 10 mars 2011 07:21

              Edited by: 843327 on 10 mars 2011 07:34

              Edited by: 843327 on 10 mars 2011 07:43

              Edited by: 843327 on 10 mars 2011 07:46