Java Code Examples for java.io.InvalidObjectException

The following examples show how to use java.io.InvalidObjectException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Object toJavaTypeData(Object data)
    throws OpenDataException, InvalidObjectException {

    // If the base element type is a basic type
    // return the data as no conversion is needed.
    if (baseElementType.isBasicType()) {
        return data;
    }

    final Object[] openArray = (Object[]) data;
    final Object[] array = (Object[])
        Array.newInstance((Class) componentType.getJavaType(),
                          openArray.length);
    int i = 0;
    for (Object o : openArray) {
        if (o == null) {
            array[i] = null;
        } else {
            array[i] = componentType.toJavaTypeData(o);
        }
        i++;
    }
    return array;
}
 
Example 2
/**
 * This method can replace a deserialized instance of this
 * class with another instance.  For example, it might replace
 * a deserialized empty ImmutableDescriptor with
 * {@link #EMPTY_DESCRIPTOR}.
 *
 * @return the replacement object, which may be {@code this}.
 *
 * @throws InvalidObjectException if the read object has invalid fields.
 */
private Object readResolve() throws InvalidObjectException {

    boolean bad = false;
    if (names == null || values == null || names.length != values.length)
        bad = true;
    if (!bad) {
        if (names.length == 0 && getClass() == ImmutableDescriptor.class)
            return EMPTY_DESCRIPTOR;
        final Comparator<String> compare = String.CASE_INSENSITIVE_ORDER;
        String lastName = ""; // also catches illegal null name
        for (int i = 0; i < names.length; i++) {
            if (names[i] == null ||
                    compare.compare(lastName, names[i]) >= 0) {
                bad = true;
                break;
            }
            lastName = names[i];
        }
    }
    if (bad)
        throw new InvalidObjectException("Bad names or values");

    return this;
}
 
Example 3
private static void setLongField(Object o, Class<?> c, String fieldName, long v)
{
    try {
        Field fld = getDeclaredField( c, fieldName ) ;
        if ((fld != null) && (fld.getType() == Long.TYPE)) {
            long key = bridge.objectFieldOffset( fld ) ;
            bridge.putLong( o, key, v ) ;
        } else {
            throw new InvalidObjectException("Field Type mismatch");
        }
    } catch (Exception e) {
        if (o != null) {
            throw utilWrapper.errorSetLongField( e, fieldName,
                o.toString(),
                new Long(v) ) ;
        } else {
            throw utilWrapper.errorSetLongField( e, fieldName,
                "null " + c.getName() + " object",
                new Long(v) ) ;
        }
    }
}
 
Example 4
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final TabularData table = (TabularData) openValue;
    final Collection<CompositeData> rows = cast(table.values());
    final Map<Object, Object> valueMap =
        sortedMap ? newSortedMap() : newInsertionOrderMap();
    for (CompositeData row : rows) {
        final Object key =
            keyMapping.fromOpenValue(row.get("key"));
        final Object value =
            valueMapping.fromOpenValue(row.get("value"));
        if (valueMap.put(key, value) != null) {
            final String msg =
                "Duplicate entry in TabularData: key=" + key;
            throw new InvalidObjectException(msg);
        }
    }
    return valueMap;
}
 
Example 5
private static void setShortField(Object o, Class<?> c, String fieldName, short v)
{
    try {
        Field fld = getDeclaredField( c, fieldName ) ;
        if ((fld != null) && (fld.getType() == Short.TYPE)) {
            long key = bridge.objectFieldOffset( fld ) ;
            bridge.putShort( o, key, v ) ;
        } else {
            throw new InvalidObjectException("Field Type mismatch");
        }
    } catch (Exception e) {
        if (o != null) {
        throw utilWrapper.errorSetShortField( e, fieldName,
            o.toString(),
            new Short(v) ) ;
        } else {
            throw utilWrapper.errorSetShortField( e, fieldName,
                "null " + c.getName() + " object",
                new Short(v) ) ;
        }
    }
}
 
Example 6
/**
 * This method can replace a deserialized instance of this
 * class with another instance.  For example, it might replace
 * a deserialized empty ImmutableDescriptor with
 * {@link #EMPTY_DESCRIPTOR}.
 *
 * @return the replacement object, which may be {@code this}.
 *
 * @throws InvalidObjectException if the read object has invalid fields.
 */
private Object readResolve() throws InvalidObjectException {

    boolean bad = false;
    if (names == null || values == null || names.length != values.length)
        bad = true;
    if (!bad) {
        if (names.length == 0 && getClass() == ImmutableDescriptor.class)
            return EMPTY_DESCRIPTOR;
        final Comparator<String> compare = String.CASE_INSENSITIVE_ORDER;
        String lastName = ""; // also catches illegal null name
        for (int i = 0; i < names.length; i++) {
            if (names[i] == null ||
                    compare.compare(lastName, names[i]) >= 0) {
                bad = true;
                break;
            }
            lastName = names[i];
        }
    }
    if (bad)
        throw new InvalidObjectException("Bad names or values");

    return this;
}
 
Example 7
@Override
public final Object fromOpenValue(Object openValue)
throws InvalidObjectException {
    if (openValue == null)
        return null;
    else
        return fromNonNullOpenValue(openValue);
}
 
Example 8
Source Project: jdk1.8-source-analysis   Source File: WeekFields.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return the singleton WeekFields associated with the
 * {@code firstDayOfWeek} and {@code minimalDays}.
 * @return the singleton WeekFields for the firstDayOfWeek and minimalDays.
 * @throws InvalidObjectException if the serialized object has invalid
 *     values for firstDayOfWeek or minimalDays.
 */
private Object readResolve() throws InvalidObjectException {
    try {
        return WeekFields.of(firstDayOfWeek, minimalDays);
    } catch (IllegalArgumentException iae) {
        throw new InvalidObjectException("Invalid serialized WeekFields: " + iae.getMessage());
    }
}
 
Example 9
Source Project: jdk8u-jdk   Source File: MappedMXBeanType.java    License: GNU General Public License v2.0 5 votes vote down vote up
Object toJavaTypeData(Object data)
    throws OpenDataException, InvalidObjectException {

    final TabularData td = (TabularData) data;

    Map<Object, Object> result = new HashMap<>();
    for (CompositeData row : (Collection<CompositeData>) td.values()) {
        Object key = keyType.toJavaTypeData(row.get(KEY));
        Object value = valueType.toJavaTypeData(row.get(VALUE));
        result.put(key, value);
    }
    return result;
}
 
Example 10
final Object fromCompositeData(CompositeData cd,
                               String[] itemNames,
                               MXBeanMapping[] converters)
        throws InvalidObjectException {
    try {
        return MethodUtil.invoke(fromMethod, null, new Object[] {cd});
    } catch (Exception e) {
        final String msg = "Failed to invoke from(CompositeData)";
        throw invalidObjectException(msg, e);
    }
}
 
Example 11
final Object fromCompositeData(CompositeData cd,
                               String[] itemNames,
                               MXBeanMapping[] converters)
        throws InvalidObjectException {
    try {
        return MethodUtil.invoke(fromMethod, null, new Object[] {cd});
    } catch (Exception e) {
        final String msg = "Failed to invoke from(CompositeData)";
        throw invalidObjectException(msg, e);
    }
}
 
Example 12
void checkCallFromOpen() {
    try {
        for (MXBeanMapping paramConverter : paramMappings)
            paramConverter.checkReconstructible();
    } catch (InvalidObjectException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 13
String applicable(Method[] getters) {
    for (int i = 0; i < getters.length; i++) {
        try {
            getterConverters[i].checkReconstructible();
        } catch (InvalidObjectException e) {
            possibleCause = e;
            return "method " + getters[i].getName() + " returns type " +
                "that cannot be mapped back from OpenData";
        }
    }
    return "";
}
 
Example 14
Source Project: JDKSourceCode1.8   Source File: MessageFormat.java    License: MIT License 5 votes vote down vote up
/**
 * Resolves instances being deserialized to the predefined constants.
 *
 * @throws InvalidObjectException if the constant could not be
 *         resolved.
 * @return resolved MessageFormat.Field constant
 */
protected Object readResolve() throws InvalidObjectException {
    if (this.getClass() != MessageFormat.Field.class) {
        throw new InvalidObjectException("subclass didn't correctly implement readResolve");
    }

    return ARGUMENT;
}
 
Example 15
Source Project: jdk8u-jdk   Source File: ValueRange.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restore the state of an ValueRange from the stream.
 * Check that the values are valid.
 *
 * @param s the stream to read
 * @throws InvalidObjectException if
 *     the smallest minimum is greater than the smallest maximum,
 *  or the smallest maximum is greater than the largest maximum
 *  or the largest minimum is greater than the largest maximum
 * @throws ClassNotFoundException if a class cannot be resolved
 */
private void readObject(ObjectInputStream s)
     throws IOException, ClassNotFoundException, InvalidObjectException
{
    s.defaultReadObject();
    if (minSmallest > minLargest) {
        throw new InvalidObjectException("Smallest minimum value must be less than largest minimum value");
    }
    if (maxSmallest > maxLargest) {
        throw new InvalidObjectException("Smallest maximum value must be less than largest maximum value");
    }
    if (minLargest > maxLargest) {
        throw new InvalidObjectException("Minimum value must be less than maximum value");
    }
}
 
Example 16
/**
 * After reading an object from the input stream, the format
 * pattern in the object is verified.
 * <p>
 * @exception InvalidObjectException if the pattern is invalid
 */
private void readObject(ObjectInputStream stream)
                     throws IOException, ClassNotFoundException {
    stream.defaultReadObject();

    try {
        compiledPattern = compile(pattern);
    } catch (Exception e) {
        throw new InvalidObjectException("invalid pattern");
    }

    if (serialVersionOnStream < 1) {
        // didn't have defaultCenturyStart field
        initializeDefaultCentury();
    }
    else {
        // fill in dependent transient field
        parseAmbiguousDatesAsAfter(defaultCenturyStart);
    }
    serialVersionOnStream = currentSerialVersion;

    // If the deserialized object has a SimpleTimeZone, try
    // to replace it with a ZoneInfo equivalent in order to
    // be compatible with the SimpleTimeZone-based
    // implementation as much as possible.
    TimeZone tz = getTimeZone();
    if (tz instanceof SimpleTimeZone) {
        String id = tz.getID();
        TimeZone zi = TimeZone.getTimeZone(id);
        if (zi != null && zi.hasSameRules(tz) && zi.getID().equals(id)) {
            setTimeZone(zi);
        }
    }
}
 
Example 17
Source Project: jdk8u60   Source File: ValueRange.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restore the state of an ValueRange from the stream.
 * Check that the values are valid.
 *
 * @param s the stream to read
 * @throws InvalidObjectException if
 *     the smallest minimum is greater than the smallest maximum,
 *  or the smallest maximum is greater than the largest maximum
 *  or the largest minimum is greater than the largest maximum
 * @throws ClassNotFoundException if a class cannot be resolved
 */
private void readObject(ObjectInputStream s)
     throws IOException, ClassNotFoundException, InvalidObjectException
{
    s.defaultReadObject();
    if (minSmallest > minLargest) {
        throw new InvalidObjectException("Smallest minimum value must be less than largest minimum value");
    }
    if (maxSmallest > maxLargest) {
        throw new InvalidObjectException("Smallest maximum value must be less than largest maximum value");
    }
    if (minLargest > maxLargest) {
        throw new InvalidObjectException("Minimum value must be less than maximum value");
    }
}
 
Example 18
Source Project: JDKSourceCode1.8   Source File: JMXPrincipal.java    License: MIT License 5 votes vote down vote up
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField gf = ois.readFields();
    String principalName = (String)gf.get("name", null);
    try {
        validate(principalName);
        this.name = principalName;
    } catch (NullPointerException e) {
        throw new InvalidObjectException(e.getMessage());
    }
}
 
Example 19
private void readObject(ObjectInputStream in)
     throws IOException, ClassNotFoundException {

    // Reading private fields of base class
    in.defaultReadObject();
    try {
        validate(super.getName(),super.getActions());
    } catch (IllegalArgumentException e) {
        throw new InvalidObjectException(e.getMessage());
    }
}
 
Example 20
Source Project: openjdk-jdk9   Source File: WeekFields.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the singleton WeekFields associated with the
 * {@code firstDayOfWeek} and {@code minimalDays}.
 * @return the singleton WeekFields for the firstDayOfWeek and minimalDays.
 * @throws InvalidObjectException if the serialized object has invalid
 *     values for firstDayOfWeek or minimalDays.
 */
private Object readResolve() throws InvalidObjectException {
    try {
        return WeekFields.of(firstDayOfWeek, minimalDays);
    } catch (IllegalArgumentException iae) {
        throw new InvalidObjectException("Invalid serialized WeekFields: " + iae.getMessage());
    }
}
 
Example 21
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    MXBeanLookup lookup = lookupNotNull(InvalidObjectException.class);
    ObjectName name = (ObjectName) openValue;
    Object mxbean =
        lookup.objectNameToMXBean(name, (Class<?>) getJavaType());
    if (mxbean == null) {
        final String msg =
            "No MXBean for name: " + name;
        throw new InvalidObjectException(msg);
    }
    return mxbean;
}
 
Example 22
Source Project: jdk1.8-source-analysis   Source File: ChoiceFormat.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * After reading an object from the input stream, do a simple verification
 * to maintain class invariants.
 * @throws InvalidObjectException if the objects read from the stream is invalid.
 */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    if (choiceLimits.length != choiceFormats.length) {
        throw new InvalidObjectException(
                "limits and format arrays of different length.");
    }
}
 
Example 23
Source Project: fitnotifications   Source File: NumberFormat.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * First, read in the default serializable data.
 *
 * Then, if <code>serialVersionOnStream</code> is less than 1, indicating that
 * the stream was written by JDK 1.1,
 * set the <code>int</code> fields such as <code>maximumIntegerDigits</code>
 * to be equal to the <code>byte</code> fields such as <code>maxIntegerDigits</code>,
 * since the <code>int</code> fields were not present in JDK 1.1.
 * Finally, set serialVersionOnStream back to the maximum allowed value so that
 * default serialization will work properly if this object is streamed out again.
 */
private void readObject(ObjectInputStream stream)
     throws IOException, ClassNotFoundException
{
    stream.defaultReadObject();
    ///CLOVER:OFF
    // we don't have serialization data for this format
    if (serialVersionOnStream < 1) {
        // Didn't have additional int fields, reassign to use them.
        maximumIntegerDigits = maxIntegerDigits;
        minimumIntegerDigits = minIntegerDigits;
        maximumFractionDigits = maxFractionDigits;
        minimumFractionDigits = minFractionDigits;
    }
    if (serialVersionOnStream < 2) {
        // Didn't have capitalizationSetting, set it to default
        capitalizationSetting = DisplayContext.CAPITALIZATION_NONE;
    }
    ///CLOVER:ON
    /*Bug 4185761
      Validate the min and max fields [Richard/GCL]
    */
    if (minimumIntegerDigits > maximumIntegerDigits ||
        minimumFractionDigits > maximumFractionDigits ||
        minimumIntegerDigits < 0 || minimumFractionDigits < 0) {
        throw new InvalidObjectException("Digit count range invalid");
    }
    serialVersionOnStream = currentSerialVersion;
}
 
Example 24
/**
 * Return the singleton WeekFields associated with the
 * {@code firstDayOfWeek} and {@code minimalDays}.
 * @return the singleton WeekFields for the firstDayOfWeek and minimalDays.
 * @throws InvalidObjectException if the serialized object has invalid
 *     values for firstDayOfWeek or minimalDays.
 */
private Object readResolve() throws InvalidObjectException {
    try {
        return WeekFields.of(firstDayOfWeek, minimalDays);
    } catch (IllegalArgumentException iae) {
        throw new InvalidObjectException("Invalid serialized WeekFields: " + iae.getMessage());
    }
}
 
Example 25
Source Project: openjdk-jdk8u   Source File: TextAttribute.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Resolves instances being deserialized to the predefined constants.
 */
protected Object readResolve() throws InvalidObjectException {
    if (this.getClass() != TextAttribute.class) {
        throw new InvalidObjectException(
            "subclass didn't correctly implement readResolve");
    }

    TextAttribute instance = instanceMap.get(getName());
    if (instance != null) {
        return instance;
    } else {
        throw new InvalidObjectException("unknown attribute name");
    }
}
 
Example 26
protected Object readResolve()
  throws ObjectStreamException
{
  try
  {
    return forName(literalName);
  } catch (IllegalArgumentException e) {
    throw new InvalidObjectException(e.getMessage());
  }
}
 
Example 27
Source Project: component-runtime   Source File: ProcessorImpl.java    License: Apache License 2.0 5 votes vote down vote up
Object readResolve() throws ObjectStreamException {
    try {
        return new ProcessorImpl(component, name, plugin, internalConfiguration, loadDelegate(value, plugin));
    } catch (final IOException | ClassNotFoundException e) {
        final InvalidObjectException invalidObjectException = new InvalidObjectException(e.getMessage());
        invalidObjectException.initCause(e);
        throw invalidObjectException;
    }
}
 
Example 28
/**
 * Resolves instances being deserialized to the predefined constants.
 */
protected Object readResolve() throws InvalidObjectException {
    if (this.getClass() != TextAttribute.class) {
        throw new InvalidObjectException(
            "subclass didn't correctly implement readResolve");
    }

    TextAttribute instance = instanceMap.get(getName());
    if (instance != null) {
        return instance;
    } else {
        throw new InvalidObjectException("unknown attribute name");
    }
}
 
Example 29
Source Project: DeskChan   Source File: Sprite.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Sprite getSpriteFromFile(File path) throws Exception {
    if (!path.exists()) throw new FileNotFoundException("Not found: "+path);
    Sprite sprite;
    if (SVGSprite.canRead(path)) {
        sprite = SVGSprite.create(path);
    } else if (ImageSprite.canRead(path)) {
        sprite = ImageSprite.create(path);
    } else if (path.toString().contains(" ") || path.toString().contains("#")){
        throw new InvalidPathException(path.toString(), "Path of file contains invalid symbols such as spaces or sharps");
    } else {
        throw new InvalidObjectException("Cannot load sprite from file "+ path + ", unknown type of file");
    }

    return sprite;
}
 
Example 30
private void readObject(ObjectInputStream stream)
    throws ClassNotFoundException, IOException {
    stream.defaultReadObject();
    if (reason == null) {
        reason = BasicReason.UNSPECIFIED;
    }
    if (certPath == null && index != -1) {
        throw new InvalidObjectException("certpath is null and index != -1");
    }
    if (index < -1 ||
        (certPath != null && index >= certPath.getCertificates().size())) {
        throw new InvalidObjectException("index out of range");
    }
}