2 Replies Latest reply on Jun 24, 2010 10:41 AM by Clebert Suconic

    Why ObjectInputStreamWithClassLoader overrides resolveClass method?

    Yong Hao Gao Master

      Hi,

       

      I'm trying to understand class ObjectInputStreamWithClassLoader's method resolveClass(). In that method, it tries to use the thread context classloader to load the class, as opposed to it's super method

       

         protected Class resolveClass(final ObjectStreamClass desc) throws IOException, ClassNotFoundException
         {
            String name = desc.getName();
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            try
            {
               Class clazz = loader.loadClass(name);
               // sanity check only.. if a classLoader can't find a clazz, it will throw an exception
               if (clazz == null)
               {
                  return super.resolveClass(desc);
               }
               else
               {
                  return clazz;
               }
            }
            catch (ClassNotFoundException e)
            {
               return super.resolveClass(desc);
            }

       

      My question is why does it so implemented? What's wrong if we just use the super method?

       

      Thanks