Package java.io

Examples of java.io.InvalidClassException


      this.constructorArgTypes = (Class<?>[]) in.readObject();
      this.constructorArgs = (Object[]) in.readObject();
    } catch (final IOException ex) {
      throw (ObjectStreamException) new StreamCorruptedException().initCause(ex);
    } catch (final ClassNotFoundException ex) {
      throw (ObjectStreamException) new InvalidClassException(ex.getLocalizedMessage()).initCause(ex);
    }

    final Map<String, ResultLoaderMap.LoadPair> arrayProps = new HashMap<String, ResultLoaderMap.LoadPair>(this.unloadedProperties);
    final List<Class<?>> arrayTypes = Arrays.asList(this.constructorArgTypes);
    final List<Object> arrayValues = Arrays.asList(this.constructorArgs);
View Full Code Here


        return this;
    }

    protected Object readResolve() throws ObjectStreamException
    {
        throw new InvalidClassException("You should be using the proxy for serialization of ImmutableMultimaps");
    }
View Full Code Here

    {
      obj = objIn.readObject();
    }
    catch (ClassNotFoundException ex)
    {
      throw new InvalidClassException(ex.toString());
    }
   
    return obj;
  }
View Full Code Here

                        for (int i = 0; i < tmpInt; i++) {
                            write(array[i] ? 1 : 0);
                        }
                        return;
                    } else {
                        throw new InvalidClassException(clazz.getName());
                    }
                } else {
                    Object[] array = (Object[]) obj;
                    int length = array.length;

                    write((length >>> 24) & 0xFF);
                    write((length >>> 16) & 0xFF);
                    write((length >>> 8) & 0xFF);
                    write((length >>> 0) & 0xFF);

                    for (int i = 0; i < length; i++)
                        writeObject(array[i]);
                }
                return;
            }
            write(TC_OBJECT);
            writeObject(classDesc);
            assignWireOffset(obj);

            if (classDesc.isExternalizable()) {
                writeExternal((Externalizable) obj);
                return;
            }

            int stackMark = classDescStack.size();
            try {

                ClassDescriptor superClassDesc;
                while ((superClassDesc = classDesc.getSuperclass()) != null) {
                    classDescStack.push(classDesc);
                    classDesc = superClassDesc;
                }

                do {
                    if (classDesc.hasWriteObjectMethod()) {
                        /* DMB:  NOT COMPLETE - Should start writing in block data format
                         * and state the size of the data to come.
                         */

                        /* DMB:  NOT COMPLETE - Should Invoke the writeObject
                         * mehtod on the object.
                         * Invoking the write object method requires a
                         * sublcass of java.io.ObjectOutputStream to be
                         * passed in.  This implementation is not a subclass
                         * of java.io.ObjectOutputStream.
                         */

                        /* DMB:  NOT COMPLETE - Should stop writing in block data format.
                         * Denote the end of this mode by writing a terminator to the stream.
                         */

                    } else {
                        FieldDescriptor[] fields = classDesc.getFields();
                        Field field;
                        if (fields.length > 0) {
                            for (int i = 0; i < fields.length; i++) {
                                field = fields[i].getField();
                                if (field == null) throw new InvalidClassException(clazz.getName(), "Nonexistent field " + fields[i].getName());
                                try {
                                    switch (fields[i].getTypeCode()) {
                                        case 'B':
                                            write(field.getByte(obj));
                                            break;
                                        case 'C':
                                            char charvalue = field.getChar(obj);
                                            write((charvalue >>> 8) & 0xFF);
                                            write((charvalue >>> 0) & 0xFF);
                                            break;
                                        case 'I':
                                            int intvalue = field.getInt(obj);
                                            write((intvalue >>> 24) & 0xFF);
                                            write((intvalue >>> 16) & 0xFF);
                                            write((intvalue >>> 8) & 0xFF);
                                            write((intvalue >>> 0) & 0xFF);
                                            break;
                                        case 'Z':
                                            write((field.getBoolean(obj) ? 1 : 0));
                                            break;
                                        case 'J':
                                            long longvalue = field.getLong(obj);
                                            write((int) (longvalue >>> 56) & 0xFF);
                                            write((int) (longvalue >>> 48) & 0xFF);
                                            write((int) (longvalue >>> 40) & 0xFF);
                                            write((int) (longvalue >>> 32) & 0xFF);
                                            write((int) (longvalue >>> 24) & 0xFF);
                                            write((int) (longvalue >>> 16) & 0xFF);
                                            write((int) (longvalue >>> 8) & 0xFF);
                                            write((int) (longvalue >>> 0) & 0xFF);
                                            break;
                                        case 'F':
                                            int floatvalue = Float.floatToIntBits(field.getFloat(obj));
                                            write((floatvalue >>> 24) & 0xFF);
                                            write((floatvalue >>> 16) & 0xFF);
                                            write((floatvalue >>> 8) & 0xFF);
                                            write((floatvalue >>> 0) & 0xFF);
                                            break;
                                        case 'D':
                                            long doublevalue = Double.doubleToLongBits(field.getDouble(obj));
                                            write((int) (doublevalue >>> 56) & 0xFF);
                                            write((int) (doublevalue >>> 48) & 0xFF);
                                            write((int) (doublevalue >>> 40) & 0xFF);
                                            write((int) (doublevalue >>> 32) & 0xFF);
                                            write((int) (doublevalue >>> 24) & 0xFF);
                                            write((int) (doublevalue >>> 16) & 0xFF);
                                            write((int) (doublevalue >>> 8) & 0xFF);
                                            write((int) (doublevalue >>> 0) & 0xFF);
                                            break;
                                        case 'S':
                                            short shortvalue = field.getShort(obj);
                                            write((shortvalue >>> 8) & 0xFF);
                                            write((shortvalue >>> 0) & 0xFF);
                                            break;
                                        case '[':
                                        case 'L':
                                            writeObject(field.get(obj));
                                            break;
                                        default:
                                            throw new InvalidClassException(clazz.getName());
                                    }
                                } catch (IllegalAccessException e) {
                                    throw (InvalidClassException)new InvalidClassException(clazz.getName(), e.getMessage()).initCause(e);
                                } finally {
                                }
                            }
                        }
                    }
View Full Code Here

        if (!type.isPrimitive()) out.writeString(typeString);
    }

    public void write(Object o, ObjectOutputStream out) throws IOException, InvalidClassException {

        if (field == null) throw new InvalidClassException(classDesc.forClass().getName(), "Nonexistent field " + name);
        try {
            switch (typeCode) {
                case 'B':
                    out.writeByte(field.getByte(o));
                    break;
                case 'C':
                    out.writeChar(field.getChar(o));
                    break;
                case 'I':
                    out.writeInt(field.getInt(o));
                    break;
                case 'Z':
                    out.writeBoolean(field.getBoolean(o));
                    break;
                case 'J':
                    out.writeLong(field.getLong(o));
                    break;
                case 'F':
                    out.writeFloat(field.getFloat(o));
                    break;
                case 'D':
                    out.writeDouble(field.getDouble(o));
                    break;
                case 'S':
                    out.writeShort(field.getShort(o));
                    break;
                case '[':
                case 'L':
                    out.writeObject(field.get(o));
                    break;
                default:
                    throw new InvalidClassException(classDesc.forClass().getName());
            }
        }
        catch (IllegalAccessException e) {
            throw (InvalidClassException)new InvalidClassException(classDesc.forClass().getName(), e.getMessage()).initCause(e);
        }
    }
View Full Code Here

                        Externalizable ext = (Externalizable)currentObject;
                        ext.readExternal(this);
                }
            } catch (InvocationTargetException e) {
                InvalidClassException exc = new InvalidClassException(
                    currentClass.getName(),
                    "InvocationTargetException accessing no-arg constructor");
                exc.initCause( e ) ;
                throw exc ;
            } catch (UnsupportedOperationException e) {
                InvalidClassException exc = new InvalidClassException(
                    currentClass.getName(),
                    "UnsupportedOperationException accessing no-arg constructor");
                exc.initCause( e ) ;
                throw exc ;
            } catch (InstantiationException e) {
                InvalidClassException exc = new InvalidClassException(
                    currentClass.getName(),
                    "InstantiationException accessing no-arg constructor");
                exc.initCause( e ) ;
                throw exc ;
            }
        } // end : if (currentClassDesc.isExternalizable())
        else {
            /* Count number of classes and descriptors we might have
             * to work on.
             */

            ObjectStreamClass currdesc = currentClassDesc;
            Class currclass = currentClass;

            int spBase = spClass;       // current top of stack

            /* The object's classes should be processed from supertype to subtype
             * Push all the clases of the current object onto a stack.
             * Note that only the serializable classes are represented
             * in the descriptor list.
             *
             * Handle versioning where one or more supertypes of
             * have been inserted or removed.  The stack will
             * contain pairs of descriptors and the corresponding
             * class.  If the object has a class that did not occur in
             * the original the descriptor will be null.  If the
             * original object had a descriptor for a class not
             * present in the local hierarchy of the object the class will be
             * null.
             *
             */

            /*
             * This is your basic diff pattern, made simpler
             * because reordering is not allowed.
             */
            // sun.4296963 ibm.11861
            // d11861 we should stop when we find the highest serializable class
            // We need this so that when we allocate the new object below, we
            // can call the constructor of the non-serializable superclass.
            // Note that in the JRMP variant of this code the
            // ObjectStreamClass.lookup() method handles this, but we've put
            // this fix here rather than change lookup because the new behaviour
            // is needed in other cases.

            for (currdesc = currentClassDesc, currclass = currentClass;
                 currdesc != null && currdesc.isSerializable();   /*sun.4296963 ibm.11861*/
                 currdesc = currdesc.getSuperclass()) {

                /*
                 * Search the classes to see if the class of this
                 * descriptor appears further up the hierarchy. Until
                 * it's found assume its an inserted class.  If it's
                 * not found, its the descriptor's class that has been
                 * removed.
                 */
                Class cc = currdesc.forClass();
                Class cl;
                for (cl = currclass; cl != null; cl = cl.getSuperclass()) {
                    if (cc == cl) {
                        // found a superclass that matches this descriptor
                        break;
                    } else {
                        /* Ignore a class that doesn't match.  No
                         * action is needed since it is already
                         * initialized.
                         */
                    }
                } // end : for (cl = currclass; cl != null; cl = cl.getSuperclass())
                /* Test if there is room for this new entry.
                 * If not, double the size of the arrays and copy the contents.
                 */
                spClass++;
                if (spClass >= classes.length) {
                    int newlen = classes.length * 2;
                    Class[] newclasses = new Class[newlen];
                    ObjectStreamClass[] newclassdesc = new ObjectStreamClass[newlen];

                    System.arraycopy(classes, 0,
                                     newclasses, 0,
                                     classes.length);
                    System.arraycopy(classdesc, 0,
                                     newclassdesc, 0,
                                     classes.length);

                    classes = newclasses;
                    classdesc = newclassdesc;
                }

                if (cl == null) {
                    /* Class not found corresponding to this descriptor.
                     * Pop off all the extra classes pushed.
                     * Push the descriptor and a null class.
                     */
                    classdesc[spClass] = currdesc;
                    classes[spClass] = null;
                } else {
                    /* Current class descriptor matches current class.
                     * Some classes may have been inserted.
                     * Record the match and advance the class, continue
                     * with the next descriptor.
                     */
                    classdesc[spClass] = currdesc;
                    classes[spClass] = cl;
                    currclass = cl.getSuperclass();
                }
            } // end : for (currdesc = currentClassDesc, currclass = currentClass;

            /* Allocate a new object.  The object is only constructed
             * above the highest serializable class and is set to
             * default values for all more specialized classes.
             */
            try {
                currentObject = (currentClass == null) ?
                    null : currentClassDesc.newInstance() ;

                // Store this object and its beginning position
                // since there might be indirections to it while
                // it's been unmarshalled.
                activeRecursionMgr.addObject(offset, currentObject);
            } catch (InvocationTargetException e) {
                InvalidClassException exc = new InvalidClassException(
                    currentClass.getName(),
                    "InvocationTargetException accessing no-arg constructor");
                exc.initCause( e ) ;
                throw exc ;
            } catch (UnsupportedOperationException e) {
                InvalidClassException exc = new InvalidClassException(
                    currentClass.getName(),
                    "UnsupportedOperationException accessing no-arg constructor");
                exc.initCause( e ) ;
                throw exc ;
            } catch (InstantiationException e) {
                InvalidClassException exc = new InvalidClassException(
                    currentClass.getName(),
                    "InstantiationException accessing no-arg constructor");
                exc.initCause( e ) ;
                throw exc ;
            }

            /*
             * For all the pushed descriptors and classes.
View Full Code Here

                        Externalizable ext = (Externalizable)currentObject;
                        ext.readExternal(this);
                    }
                } catch (InvocationTargetException e) {
                    InvalidClassException exc = new InvalidClassException(
                        currentClass.getName(),
                        "InvocationTargetException accessing no-arg constructor");
                    exc.initCause( e ) ;
                    throw exc ;
                } catch (UnsupportedOperationException e) {
                    InvalidClassException exc = new InvalidClassException(
                        currentClass.getName(),
                        "UnsupportedOperationException accessing no-arg constructor");
                    exc.initCause( e ) ;
                    throw exc ;
                } catch (InstantiationException e) {
                    InvalidClassException exc = new InvalidClassException(
                        currentClass.getName(),
                        "InstantiationException accessing no-arg constructor");
                    exc.initCause( e ) ;
                    throw exc ;
                }
            } else {
                /*
                 * This is your basic diff pattern, made simpler
                 * because reordering is not allowed.
                 */
                for (currdesc = currentClassDesc, currclass = currentClass;
                     currdesc != null && currdesc.isSerializable();   /*sun.4296963 ibm.11861*/

                     currdesc = currdesc.getSuperclass()) {

                    /*
                     * Search the classes to see if the class of this
                     * descriptor appears further up the hierarchy. Until
                     * it's found assume its an inserted class.  If it's
                     * not found, its the descriptor's class that has been
                     * removed.
                     */
                    Class cc = currdesc.forClass();
                    Class cl;
                    for (cl = currclass; cl != null; cl = cl.getSuperclass()) {
                        if (cc == cl) {
                            // found a superclass that matches this descriptor
                            break;
                        } else {
                            /* Ignore a class that doesn't match.  No
                             * action is needed since it is already
                             * initialized.
                             */
                        }
                    } // end : for (cl = currclass; cl != null; cl = cl.getSuperclass())
                    /* Test if there is room for this new entry.
                     * If not, double the size of the arrays and copy the contents.
                     */
                    spClass++;
                    if (spClass >= classes.length) {
                        int newlen = classes.length * 2;
                        Class[] newclasses = new Class[newlen];
                        ObjectStreamClass[] newclassdesc = new ObjectStreamClass[newlen];

                        System.arraycopy(classes, 0,
                                         newclasses, 0,
                                         classes.length);
                        System.arraycopy(classdesc, 0,
                                         newclassdesc, 0,
                                         classes.length);

                        classes = newclasses;
                        classdesc = newclassdesc;
                    }

                    if (cl == null) {
                        /* Class not found corresponding to this descriptor.
                         * Pop off all the extra classes pushed.
                         * Push the descriptor and a null class.
                         */
                        classdesc[spClass] = currdesc;
                        classes[spClass] = null;
                    } else {
                        /* Current class descriptor matches current class.
                         * Some classes may have been inserted.
                         * Record the match and advance the class, continue
                         * with the next descriptor.
                         */
                        classdesc[spClass] = currdesc;
                        classes[spClass] = cl;
                        currclass = cl.getSuperclass();
                    }
                } // end : for (currdesc = currentClassDesc, currclass = currentClass;

                /* Allocate a new object.
                 */
                try {
                    currentObject = (currentClass == null) ?
                        null : currentClassDesc.newInstance();

                    // Store this object and its beginning position
                    // since there might be indirections to it while
                    // it's been unmarshalled.
                    activeRecursionMgr.addObject(offset, currentObject);
                } catch (InvocationTargetException e) {
                    InvalidClassException exc = new InvalidClassException(
                        currentClass.getName(),
                        "InvocationTargetException accessing no-arg constructor");
                    exc.initCause( e ) ;
                    throw exc ;
                } catch (UnsupportedOperationException e) {
                    InvalidClassException exc = new InvalidClassException(
                        currentClass.getName(),
                        "UnsupportedOperationException accessing no-arg constructor");
                    exc.initCause( e ) ;
                    throw exc ;
                } catch (InstantiationException e) {
                    InvalidClassException exc = new InvalidClassException(
                        currentClass.getName(),
                        "InstantiationException accessing no-arg constructor");
                    exc.initCause( e ) ;
                    throw exc ;
                }

                Enumeration fvdsList = getOrderedDescriptions(repositoryID, sender).elements();

View Full Code Here

                    bridge.putDouble( o, field.getFieldID(), doubleValue ) ;
                    //reflective code: field.getField().setDouble( o, doubleValue ) ;
                    break;
                default:
                    // XXX I18N, logging needed.
                    throw new InvalidClassException(cl.getName());
            }
        } catch (IllegalArgumentException e) {
            /* This case should never happen. If the field types
               are not the same, InvalidClassException is raised when
               matching the local class to the serialized ObjectStreamClass. */
 
View Full Code Here

                    fieldToValueMap.put(fields[i].getName(),
                                        new Double(doubleValue));
                    break;
                default:
                    // XXX I18N, logging needed.
                    throw new InvalidClassException(currentClassDesc.getName());
            }
        }

        /* Read and set object fields from the input stream. */
        if (currentClassDesc.objFields > 0) {
View Full Code Here

                    final int idx = instanceCache.size();
                    instanceCache.add(UNRESOLVED);
                    final int size = readInt();
                    final Class<?> type = descriptor.getType();
                    if (! type.isArray()) {
                        throw new InvalidClassException(type.getName(), "Expected array type");
                    }
                    final Class<?> ct = type.getComponentType();
                    if (ct.isPrimitive()) {
                        if (ct == byte.class) {
                            final byte[] bytes = new byte[size];
                            readFully(bytes);
                            return replaceOrReturn(unshared, bytes, idx);
                        } else if (ct == short.class) {
                            final short[] shorts = new short[size];
                            for (int i = 0; i < shorts.length; i++) {
                                shorts[i] = readShort();
                            }
                            return replaceOrReturn(unshared, shorts, idx);
                        } else if (ct == int.class) {
                            final int[] ints = new int[size];
                            for (int i = 0; i < ints.length; i++) {
                                ints[i] = readInt();
                            }
                            return replaceOrReturn(unshared, ints, idx);
                        } else if (ct == long.class) {
                            final long[] longs = new long[size];
                            for (int i = 0; i < longs.length; i++) {
                                longs[i] = readLong();
                            }
                            return replaceOrReturn(unshared, longs, idx);
                        } else if (ct == float.class) {
                            final float[] floats = new float[size];
                            for (int i = 0; i < floats.length; i++) {
                                floats[i] = readFloat();
                            }
                            return replaceOrReturn(unshared, floats, idx);
                        } else if (ct == double.class) {
                            final double[] doubles = new double[size];
                            for (int i = 0; i < doubles.length; i++) {
                                doubles[i] = readDouble();
                            }
                            return replaceOrReturn(unshared, doubles, idx);
                        } else if (ct == boolean.class) {
                            final boolean[] booleans = new boolean[size];
                            for (int i = 0; i < booleans.length; i++) {
                                booleans[i] = readBoolean();
                            }
                            return replaceOrReturn(unshared, booleans, idx);
                        } else if (ct == char.class) {
                            final char[] chars = new char[size];
                            for (int i = 0; i < chars.length; i++) {
                                chars[i] = readChar();
                            }
                            return replaceOrReturn(unshared, chars, idx);
                        } else {
                            throw new InvalidClassException(type.getName(), "Invalid component type");
                        }
                    } else {
                        final Object[] objects = (Object[]) Array.newInstance(ct, size);
                        instanceCache.set(idx, objects);
                        for (int i = 0; i < objects.length; i++) {
                            objects[i] = doReadObject(false);
                        }
                        return replaceOrReturn(unshared, objects, idx);
                    }
                }

                case TC_ENUM: {
                    final Descriptor descriptor = readNonNullClassDescriptor();
                    final Class<? extends Enum> enumType;
                    try {
                        enumType = descriptor.getType().asSubclass(Enum.class);
                    } catch (ClassCastException e) {
                        throw new InvalidClassException("Expected an enum class descriptor");
                    }
                    final int idx = instanceCache.size();
                    instanceCache.add(UNRESOLVED);
                    final String constName = (String) doReadObject(false);
                    final Enum obj = Enum.valueOf(enumType, constName);
                    return replaceOrReturn(unshared, obj, idx);
                }

                case TC_OBJECT: {
                    final Descriptor descriptor = readNonNullClassDescriptor();
                    if ((descriptor.getFlags() & (SC_SERIALIZABLE | SC_EXTERNALIZABLE)) == 0) {
                        throw new NotSerializableException(descriptor.getClass().getName());
                    }
                    final Object obj;
                    final int idx;
                    final Class<?> objClass = descriptor.getType();
                    final SerializableClass sc = registry.lookup(objClass);
                    if ((descriptor.getFlags() & SC_EXTERNALIZABLE) != 0) {
                        if (sc.hasObjectInputConstructor()) {
                            obj = sc.callObjectInputConstructor(blockUnmarshaller);
                        } else if (sc.hasPublicNoArgConstructor()) {
                            obj = sc.callNoArgConstructor();
                        } else {
                            throw new InvalidClassException(objClass.getName(), "Class is non-public or has no public no-arg constructor");
                        }
                        idx = instanceCache.size();
                        instanceCache.add(unshared ? UNSHARED : obj);
                        if (obj instanceof Externalizable) {
                            final Externalizable externalizable = (Externalizable) obj;
View Full Code Here

TOP

Related Classes of java.io.InvalidClassException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.