java.io.InvalidObjectException Java Examples

The following examples show how to use java.io.InvalidObjectException. 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 check out the related API usage on the sidebar.
Example #1
Source File: IIOPInputStream.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 #2
Source File: DefaultMXBeanMappingFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@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 #3
Source File: ImmutableDescriptor.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: IIOPInputStream.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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 #5
Source File: WeekFields.java    From jdk1.8-source-analysis with 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 #6
Source File: MessageFormat.java    From JDKSourceCode1.8 with 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 #7
Source File: DefaultMXBeanMappingFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final Object fromOpenValue(Object openValue)
throws InvalidObjectException {
    if (openValue == null)
        return null;
    else
        return fromNonNullOpenValue(openValue);
}
 
Example #8
Source File: TextAttribute.java    From openjdk-jdk8u with 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 #9
Source File: WeekFields.java    From openjdk-jdk8u-backup with 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 #10
Source File: MappedMXBeanType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 #11
Source File: ChangeableKindEnum.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
protected Object readResolve()
  throws ObjectStreamException
{
  try
  {
    return forName(literalName);
  } catch (IllegalArgumentException e) {
    throw new InvalidObjectException(e.getMessage());
  }
}
 
Example #12
Source File: ValueRange.java    From jdk8u-jdk with 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 #13
Source File: MappedMXBeanType.java    From jdk8u-jdk with 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 #14
Source File: URI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reconstitutes a URI from the given serial stream.
 *
 * <p> The {@link java.io.ObjectInputStream#defaultReadObject()} method is
 * invoked to read the value of the {@code string} field.  The result is
 * then parsed in the usual way.
 *
 * @param  is  The object-input stream from which this object
 *             is being read
 */
private void readObject(ObjectInputStream is)
    throws ClassNotFoundException, IOException
{
    port = -1;                      // Argh
    is.defaultReadObject();
    try {
        new Parser(string).parse(false);
    } catch (URISyntaxException x) {
        IOException y = new InvalidObjectException("Invalid URI");
        y.initCause(x);
        throw y;
    }
}
 
Example #15
Source File: DefaultMXBeanMappingFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 #16
Source File: ProcessorImpl.java    From component-runtime with 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 #17
Source File: NumberFormat.java    From fitnotifications with 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 #18
Source File: TextAttribute.java    From openjdk-jdk8u-backup with 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 #19
Source File: DefaultMXBeanMappingFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 #20
Source File: ChoiceFormat.java    From openjdk-jdk9 with GNU General Public License v2.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 #21
Source File: CertPathValidatorException.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #22
Source File: SimpleDateFormat.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #23
Source File: ValueRange.java    From jdk8u60 with 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 #24
Source File: ImmutableDescriptor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 #25
Source File: ChoiceFormat.java    From jdk1.8-source-analysis with 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 #26
Source File: Sprite.java    From DeskChan with 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 #27
Source File: DefaultMXBeanMappingFactory.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
@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 #28
Source File: JMXPrincipal.java    From JDKSourceCode1.8 with 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 #29
Source File: WeekFields.java    From openjdk-jdk9 with 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 #30
Source File: MBeanTrustPermission.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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());
    }
}