code: private void writeObject(ObjectOutputStream stream) throws IOException {
          Object resolvedObj = getResolvedObj();
          boolean serializable = resolvedObj instanceof Serializable;
          if (resolvedObj != null && !serializable) {
              // the cause is of this type, since resolvedObj is not null
              javax.naming.NamingException namingException = (javax.naming.NamingException) getCause();
              namingException.setResolvedObj(null);
              try {
                  stream.defaultWriteObject();
              } finally {
                  namingException.setResolvedObj(resolvedObj);
              }
          } else {
              stream.defaultWriteObject();
          }
      }
docs: Checks if the <tt>resolvedObj</tt> of the causing exception is
  suspected to be non-serializable, and if so temporarily nulls it before
  calling the default serialization mechanism.
  
  @param stream
  the stream onto which this object is serialized
  @throws IOException
  if there is an error writing this object to the stream