Java Code Examples for java.io.InvalidObjectException

The following are top voted examples for showing how to use java.io.InvalidObjectException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: OpenJSharp   File: BatchUpdateException.java   View source code 6 votes vote down vote up
/**
 * readObject is called to restore the state of the
 * {@code BatchUpdateException} from a stream.
 */
private void readObject(ObjectInputStream s)
        throws IOException, ClassNotFoundException {

   ObjectInputStream.GetField fields = s.readFields();
   int[] tmp = (int[])fields.get("updateCounts", null);
   long[] tmp2 = (long[])fields.get("longUpdateCounts", null);
   if(tmp != null && tmp2 != null && tmp.length != tmp2.length)
       throw new InvalidObjectException("update counts are not the expected size");
   if (tmp != null)
       updateCounts = tmp.clone();
   if (tmp2 != null)
       longUpdateCounts = tmp2.clone();
   if(updateCounts == null && longUpdateCounts != null)
       updateCounts = copyUpdateCount(longUpdateCounts);
   if(longUpdateCounts == null && updateCounts != null)
       longUpdateCounts = copyUpdateCount(updateCounts);

}
 
Example 2
Project: openjdk-jdk10   File: URL.java   View source code 6 votes vote down vote up
private URL fabricateNewURL()
            throws InvalidObjectException {
    // create URL string from deserialized object
    URL replacementURL = null;
    String urlString = tempState.reconstituteUrlString();

    try {
        replacementURL = new URL(urlString);
    } catch (MalformedURLException mEx) {
        resetState();
        InvalidObjectException invoEx = new InvalidObjectException(
                "Malformed URL:  " + urlString);
        invoEx.initCause(mEx);
        throw invoEx;
    }
    replacementURL.setSerializedHashCode(tempState.getHashCode());
    resetState();
    return replacementURL;
}
 
Example 3
Project: jdk8u-jdk   File: InetSocketAddress.java   View source code 6 votes vote down vote up
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()
    ObjectInputStream.GetField oisFields = in.readFields();
    final String oisHostname = (String)oisFields.get("hostname", null);
    final InetAddress oisAddr = (InetAddress)oisFields.get("addr", null);
    final int oisPort = oisFields.get("port", -1);

    // Check that our invariants are satisfied
    checkPort(oisPort);
    if (oisHostname == null && oisAddr == null)
        throw new InvalidObjectException("hostname and addr " +
                                         "can't both be null");

    InetSocketAddressHolder h = new InetSocketAddressHolder(oisHostname,
                                                            oisAddr,
                                                            oisPort);
    UNSAFE.putObject(this, FIELDS_OFFSET, h);
}
 
Example 4
Project: openjdk-jdk10   File: IIOPInputStream.java   View source code 6 votes vote down vote up
private static void setCharField(Object o, Class<?> c, String fieldName, char v)
{
    try {
        Field fld = getDeclaredField( c, fieldName ) ;
        if ((fld != null) && (fld.getType() == Character.TYPE)) {
            long key = bridge.objectFieldOffset( fld ) ;
            bridge.putChar( o, key, v ) ;
        } else {
            throw new InvalidObjectException("Field Type mismatch");
        }
    } catch (Exception e) {
        if (o != null) {
            throw utilWrapper.errorSetCharField( e, fieldName,
                o.toString(),
                new Character(v) ) ;
        } else {
            throw utilWrapper.errorSetCharField( e, fieldName,
                "null " + c.getName() + " object",
                new Character(v) ) ;
        }
    }
}
 
Example 5
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   View source code 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final Object[] openArray = (Object[]) openValue;
    final Type javaType = getJavaType();
    final Object[] valueArray;
    final Type componentType;
    if (javaType instanceof GenericArrayType) {
        componentType =
            ((GenericArrayType) javaType).getGenericComponentType();
    } else if (javaType instanceof Class<?> &&
               ((Class<?>) javaType).isArray()) {
        componentType = ((Class<?>) javaType).getComponentType();
    } else {
        throw new IllegalArgumentException("Not an array: " +
                                           javaType);
    }
    valueArray = (Object[]) Array.newInstance((Class<?>) componentType,
                                              openArray.length);
    for (int i = 0; i < openArray.length; i++)
        valueArray[i] = elementMapping.fromOpenValue(openArray[i]);
    return valueArray;
}
 
Example 6
Project: jdk8u-jdk   File: URL.java   View source code 6 votes vote down vote up
private URL fabricateNewURL()
            throws InvalidObjectException {
    // create URL string from deserialized object
    URL replacementURL = null;
    String urlString = tempState.reconstituteUrlString();

    try {
        replacementURL = new URL(urlString);
    } catch (MalformedURLException mEx) {
        resetState();
        InvalidObjectException invoEx = new InvalidObjectException(
                "Malformed URL: " + urlString);
        invoEx.initCause(mEx);
        throw invoEx;
    }
    replacementURL.setSerializedHashCode(tempState.getHashCode());
    resetState();
    return replacementURL;
}
 
Example 7
Project: openjdk-jdk10   File: InetSocketAddress.java   View source code 6 votes vote down vote up
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()
    ObjectInputStream.GetField oisFields = in.readFields();
    final String oisHostname = (String)oisFields.get("hostname", null);
    final InetAddress oisAddr = (InetAddress)oisFields.get("addr", null);
    final int oisPort = oisFields.get("port", -1);

    // Check that our invariants are satisfied
    checkPort(oisPort);
    if (oisHostname == null && oisAddr == null)
        throw new InvalidObjectException("hostname and addr " +
                                         "can't both be null");

    InetSocketAddressHolder h = new InetSocketAddressHolder(oisHostname,
                                                            oisAddr,
                                                            oisPort);
    UNSAFE.putObject(this, FIELDS_OFFSET, h);
}
 
Example 8
Project: CommonInformationSpace   File: OtherContentConnectorCoreExt.java   View source code 6 votes vote down vote up
/**
 * This message is called by the ConnectorCore when a message was receive. It will be translatet to the Application
 * representation and the translatet message if send via the registered callback to the application.
 * 
 * @param msg
 * @throws InvalidObjectException
 */
public void msgReceived(CISPayload payload) throws InvalidObjectException {
	log.info("--> messageReceived");
	
	if (payload instanceof CISOtherContent) {
		CISOtherContent otherCont = (CISOtherContent)payload;
		if (otherCont.getMimeType().equalsIgnoreCase(CoreConstants.MIME_TYPE_KMZ)) {
			AppCallbackHandlerImpl.getInstance().getCallback(CoreConstants.MSGTYPE_KMZ).msgReceived(payload);
		} else if (otherCont.getMimeType().equalsIgnoreCase(CoreConstants.MIME_TYPE_WMS)) {
			AppCallbackHandlerImpl.getInstance().getCallback(CoreConstants.MSGTYPE_WMS).msgReceived(payload);
		} else if (otherCont.getMimeType().equalsIgnoreCase(CoreConstants.MIME_TYPE_WFS)) {
			AppCallbackHandlerImpl.getInstance().getCallback(CoreConstants.MSGTYPE_WFS).msgReceived(payload);
		} if (otherCont.getMimeType().equalsIgnoreCase(CoreConstants.MIME_TYPE_MLP)) {
			AppCallbackHandlerImpl.getInstance().getCallback(CoreConstants.MSGTYPE_MLP).msgReceived(payload);
		}
		
	} else {
		throw new InvalidObjectException("Object is not OtherContent Object!");
	}
	
	
	log.info("messageReceived -->");
}
 
Example 9
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   View source code 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final Object[] openArray = (Object[]) openValue;
    final Collection<Object> valueCollection;
    try {
        valueCollection = cast(collectionClass.newInstance());
    } catch (Exception e) {
        throw invalidObjectException("Cannot create collection", e);
    }
    for (Object o : openArray) {
        Object value = elementMapping.fromOpenValue(o);
        if (!valueCollection.add(value)) {
            final String msg =
                "Could not add " + o + " to " +
                collectionClass.getName() +
                " (duplicate set element?)";
            throw new InvalidObjectException(msg);
        }
    }
    return valueCollection;
}
 
Example 10
Project: OpenJSharp   File: DefaultMXBeanMappingFactory.java   View source code 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final Object[] openArray = (Object[]) openValue;
    final Type javaType = getJavaType();
    final Object[] valueArray;
    final Type componentType;
    if (javaType instanceof GenericArrayType) {
        componentType =
            ((GenericArrayType) javaType).getGenericComponentType();
    } else if (javaType instanceof Class<?> &&
               ((Class<?>) javaType).isArray()) {
        componentType = ((Class<?>) javaType).getComponentType();
    } else {
        throw new IllegalArgumentException("Not an array: " +
                                           javaType);
    }
    valueArray = (Object[]) Array.newInstance((Class<?>) componentType,
                                              openArray.length);
    for (int i = 0; i < openArray.length; i++)
        valueArray[i] = elementMapping.fromOpenValue(openArray[i]);
    return valueArray;
}
 
Example 11
Project: openjdk-jdk10   File: IIOPInputStream.java   View source code 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 12
Project: openjdk-jdk10   File: DefaultMXBeanMappingFactory.java   View source code 6 votes vote down vote up
@Override
final Object fromNonNullOpenValue(Object openValue)
        throws InvalidObjectException {
    final Object[] openArray = (Object[]) openValue;
    final Collection<Object> valueCollection;
    try {
        @SuppressWarnings("deprecation")
        Collection<?> tmp = collectionClass.newInstance();
        valueCollection = cast(tmp);
    } catch (Exception e) {
        throw invalidObjectException("Cannot create collection", e);
    }
    for (Object o : openArray) {
        Object value = elementMapping.fromOpenValue(o);
        if (!valueCollection.add(value)) {
            final String msg =
                "Could not add " + o + " to " +
                collectionClass.getName() +
                " (duplicate set element?)";
            throw new InvalidObjectException(msg);
        }
    }
    return valueCollection;
}
 
Example 13
Project: openjdk-jdk10   File: IIOPInputStream.java   View source code 6 votes vote down vote up
private static void setByteField(Object o, Class<?> c, String fieldName, byte v)
{
    try {
        Field fld = getDeclaredField( c, fieldName ) ;
        if ((fld != null) && (fld.getType() == Byte.TYPE)) {
            long key = bridge.objectFieldOffset( fld ) ;
            bridge.putByte( o, key, v ) ;
        } else {
            throw new InvalidObjectException("Field Type mismatch");
        }
    } catch (Exception e) {
        if (o != null) {
            throw utilWrapper.errorSetByteField( e, fieldName,
                o.toString(),
                new Byte(v) ) ;
        } else {
            throw utilWrapper.errorSetByteField( e, fieldName,
                "null " + c.getName() + " object",
                new Byte(v) ) ;
        }
    }
}
 
Example 14
Project: OpenJSharp   File: GcInfoCompositeData.java   View source code 5 votes vote down vote up
public static Map<String, MemoryUsage>
        getMemoryUsageAfterGc(CompositeData cd) {
    try {
        TabularData td = (TabularData) cd.get(MEMORY_USAGE_AFTER_GC);
        //return (Map<String,MemoryUsage>)
        return cast(memoryUsageMapType.toJavaTypeData(td));
    } catch (InvalidObjectException | OpenDataException e) {
        // Should never reach here
        throw new AssertionError(e);
    }
}
 
Example 15
Project: jdk8u-jdk   File: MappedMXBeanType.java   View source code 5 votes vote down vote up
Object toJavaTypeData(Object data)
    throws OpenDataException, InvalidObjectException {

    final Object[] openArray = (Object[]) data;
    List<Object> result = new ArrayList<>(openArray.length);
    for (Object o : openArray) {
        result.add(paramType.toJavaTypeData(o));
    }
    return result;
}
 
Example 16
Project: OpenJSharp   File: ChoiceFormat.java   View source code 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 17
Project: jdk8u-jdk   File: DirectoryIteratorException.java   View source code 5 votes vote down vote up
/**
 * Called to read the object from a stream.
 *
 * @throws  InvalidObjectException
 *          if the object is invalid or has a cause that is not
 *          an {@code IOException}
 */
private void readObject(ObjectInputStream s)
    throws IOException, ClassNotFoundException
{
    s.defaultReadObject();
    Throwable cause = super.getCause();
    if (!(cause instanceof IOException))
        throw new InvalidObjectException("Cause must be an IOException");
}
 
Example 18
Project: incubator-netbeans   File: VariableMirrorTranslator.java   View source code 5 votes vote down vote up
private static void setValueToFinalField(ObjectReference obj, String name, ClassType clazz, Value fv, VirtualMachine vm, ThreadReference thread) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ClassNotPreparedExceptionWrapper, ClassNotLoadedException, ObjectCollectedExceptionWrapper, IncompatibleThreadStateException, UnsupportedOperationExceptionWrapper, InvalidTypeException, InvalidObjectException {
    ObjectReference fieldRef = getDeclaredOrInheritedField(clazz, name, vm, thread);
    if (fieldRef == null) {
        InvalidObjectException ioex = new InvalidObjectException("No field "+name+" of class "+clazz);
        throw ioex;
    }
    // field.setAccessible(true);
    ClassType fieldClassType = (ClassType) ValueWrapper.type(fieldRef);
    com.sun.jdi.Method setAccessibleMethod = ClassTypeWrapper.concreteMethodByName(
            fieldClassType, "setAccessible", "(Z)V");
    try {
        ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setAccessibleMethod,
                                            Collections.singletonList(vm.mirrorOf(true)),
                                            ClassType.INVOKE_SINGLE_THREADED);
        // field.set(newInstance, fv);
        com.sun.jdi.Method setMethod = ClassTypeWrapper.concreteMethodByName(
                fieldClassType, "set", "(Ljava/lang/Object;Ljava/lang/Object;)V");
        if (fv instanceof PrimitiveValue) {
            PrimitiveType pt = (PrimitiveType) ValueWrapper.type(fv);
            ReferenceType fieldBoxingClass = EvaluatorVisitor.adjustBoxingType(clazz, pt, null);
            fv = EvaluatorVisitor.box((PrimitiveValue) fv, fieldBoxingClass, thread, null);
        }
        List<Value> args = Arrays.asList(new Value[] { obj, fv });
        ObjectReferenceWrapper.invokeMethod(fieldRef, thread, setMethod,
                                            args,
                                            ClassType.INVOKE_SINGLE_THREADED);
    } catch (InvocationException iex) {
        throw new InvalidObjectException(
                "Problem setting value "+fv+" to field "+name+" of class "+clazz+
                " : "+iex.exception());
    }
}
 
Example 19
Project: jdk8u-jdk   File: ValueRange.java   View source code 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 20
Project: openjdk-jdk10   File: MappedMXBeanType.java   View source code 5 votes vote down vote up
public static Object toJavaTypeData(Object openData, Type t)
        throws OpenDataException, InvalidObjectException {
    if (openData == null) {
        return null;
    }
    MappedMXBeanType mt = getMappedType(t);
    return mt.toJavaTypeData(openData);
}
 
Example 21
Project: CommonInformationSpace   File: CapConnectorCoreExt.java   View source code 5 votes vote down vote up
/**
 * This message is called by the ConnectorCore when a message was received. It will be translatet to the Application
 * representation and the translatet message if send via the registered callback to the application.
 * @param msg
 * @throws InvalidObjectException
 */
public void msgReceived(CISPayload payload) throws InvalidObjectException {
	log.info("--> messageReceived");
	
	//Parse your object to your domain objects here
	
	// create and forward the message to the connector
	AppCallbackHandlerImpl.getInstance().getCallback(CoreConstants.MSGTYPE_CAP).msgReceived(payload);
}
 
Example 22
Project: jdk8u-jdk   File: EnumSyntax.java   View source code 5 votes vote down vote up
/**
 * During object input, convert this deserialized enumeration instance to
 * the proper enumeration value defined in the enumeration attribute class.
 *
 * @return  The enumeration singleton value stored at index
 *          <I>i</I>-<I>L</I> in the enumeration value table returned by
 *          {@link #getEnumValueTable() getEnumValueTable()},
 *          where <I>i</I> is this enumeration value's integer value and
 *          <I>L</I> is the value returned by {@link #getOffset()
 *          getOffset()}.
 *
 * @throws ObjectStreamException if the stream can't be deserialised
 * @throws  InvalidObjectException
 *     Thrown if the enumeration value table is null, this enumeration
 *     value's integer value does not correspond to an element in the
 *     enumeration value table, or the corresponding element in the
 *     enumeration value table is null. (Note: {@link
 *     java.io.InvalidObjectException InvalidObjectException} is a subclass
 *     of {@link java.io.ObjectStreamException ObjectStreamException}, which
 *     <CODE>readResolve()</CODE> is declared to throw.)
 */
protected Object readResolve() throws ObjectStreamException {

    EnumSyntax[] theTable = getEnumValueTable();

    if (theTable == null) {
        throw new InvalidObjectException(
                            "Null enumeration value table for class " +
                            getClass());
    }

    int theOffset = getOffset();
    int theIndex = value - theOffset;

    if (0 > theIndex || theIndex >= theTable.length) {
        throw new InvalidObjectException
            ("Integer value = " +  value + " not in valid range " +
             theOffset + ".." + (theOffset + theTable.length - 1) +
             "for class " + getClass());
    }

    EnumSyntax result = theTable[theIndex];
    if (result == null) {
        throw new InvalidObjectException
            ("No enumeration value for integer value = " +
             value + "for class " + getClass());
    }
    return result;
}
 
Example 23
Project: CommonInformationSpace   File: Validator.java   View source code 5 votes vote down vote up
/**
 * This method validates if the given Object is a valid Google CAP Object.
 *  
 * @param msg The Coogle CAP Object
 * @return the valid Google CAP Object
 * @throws InvalidObjectException If the Object is no valid Google CAP object
 */
public static Alert checkIfAlertObject(Object msg) throws InvalidObjectException {
	Alert alert = null;
	if (msg instanceof Alert) {
		alert = (Alert)msg;
	} else {
		throw new InvalidObjectException("Given Object is no Alert Object!");
	}
	return alert;
}
 
Example 24
Project: OpenJSharp   File: MBeanTrustPermission.java   View source code 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());
    }
}
 
Example 25
Project: openjdk-jdk10   File: WeekFields.java   View source code 5 votes vote down vote up
/**
 * Restore the state of a WeekFields from the stream.
 * Check that the values are valid.
 *
 * @param s the stream to read
 * @throws InvalidObjectException if the serialized object has an invalid
 *     value for firstDayOfWeek or minimalDays.
 * @throws ClassNotFoundException if a class cannot be resolved
 */
private void readObject(ObjectInputStream s)
     throws IOException, ClassNotFoundException, InvalidObjectException
{
    s.defaultReadObject();
    if (firstDayOfWeek == null) {
        throw new InvalidObjectException("firstDayOfWeek is null");
    }

    if (minimalDays < 1 || minimalDays > 7) {
        throw new InvalidObjectException("Minimal number of days is invalid");
    }
}
 
Example 26
Project: openjdk-jdk10   File: TargetedNotification.java   View source code 5 votes vote down vote up
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    ois.defaultReadObject();
    try {
        validate(this.notif, this.id);
    } catch (IllegalArgumentException e) {
        throw new InvalidObjectException(e.getMessage());
    }
}
 
Example 27
Project: openjdk-jdk10   File: WeekFields.java   View source code 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 28
Project: guava-mock   File: ImmutableListMultimap.java   View source code 5 votes vote down vote up
@GwtIncompatible // java.io.ObjectInputStream
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
  stream.defaultReadObject();
  int keyCount = stream.readInt();
  if (keyCount < 0) {
    throw new InvalidObjectException("Invalid key count " + keyCount);
  }
  ImmutableMap.Builder<Object, ImmutableList<Object>> builder = ImmutableMap.builder();
  int tmpSize = 0;

  for (int i = 0; i < keyCount; i++) {
    Object key = stream.readObject();
    int valueCount = stream.readInt();
    if (valueCount <= 0) {
      throw new InvalidObjectException("Invalid value count " + valueCount);
    }

    ImmutableList.Builder<Object> valuesBuilder = ImmutableList.builder();
    for (int j = 0; j < valueCount; j++) {
      valuesBuilder.add(stream.readObject());
    }
    builder.put(key, valuesBuilder.build());
    tmpSize += valueCount;
  }

  ImmutableMap<Object, ImmutableList<Object>> tmpMap;
  try {
    tmpMap = builder.build();
  } catch (IllegalArgumentException e) {
    throw (InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e);
  }

  FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap);
  FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize);
}
 
Example 29
Project: jdk8u-jdk   File: TextAttribute.java   View source code 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 30
Project: openjdk-jdk10   File: JComponent.java   View source code 5 votes vote down vote up
/**
 * This is the method that's called after the entire graph
 * of objects has been read in.  It initializes
 * the UI property of all of the copmonents with
 * <code>SwingUtilities.updateComponentTreeUI</code>.
 */
public void validateObject() throws InvalidObjectException {
    try {
        for (JComponent root : roots) {
            SwingUtilities.updateComponentTreeUI(root);
        }
    }
    finally {
        readObjectCallbacks.remove(inputStream);
    }
}
 
Example 31
Project: googles-monorepo-demo   File: ImmutableListMultimap.java   View source code 5 votes vote down vote up
@GwtIncompatible // java.io.ObjectInputStream
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
  stream.defaultReadObject();
  int keyCount = stream.readInt();
  if (keyCount < 0) {
    throw new InvalidObjectException("Invalid key count " + keyCount);
  }
  ImmutableMap.Builder<Object, ImmutableList<Object>> builder = ImmutableMap.builder();
  int tmpSize = 0;

  for (int i = 0; i < keyCount; i++) {
    Object key = stream.readObject();
    int valueCount = stream.readInt();
    if (valueCount <= 0) {
      throw new InvalidObjectException("Invalid value count " + valueCount);
    }

    ImmutableList.Builder<Object> valuesBuilder = ImmutableList.builder();
    for (int j = 0; j < valueCount; j++) {
      valuesBuilder.add(stream.readObject());
    }
    builder.put(key, valuesBuilder.build());
    tmpSize += valueCount;
  }

  ImmutableMap<Object, ImmutableList<Object>> tmpMap;
  try {
    tmpMap = builder.build();
  } catch (IllegalArgumentException e) {
    throw (InvalidObjectException) new InvalidObjectException(e.getMessage()).initCause(e);
  }

  FieldSettersHolder.MAP_FIELD_SETTER.set(this, tmpMap);
  FieldSettersHolder.SIZE_FIELD_SETTER.set(this, tmpSize);
}
 
Example 32
Project: fitnotifications   File: MessageFormat.java   View source code 5 votes vote down vote up
/**
 * Resolves instances being deserialized to the predefined constants.
 *
 * @return resolved MessageFormat.Field constant
 * @throws InvalidObjectException if the constant could not be resolved.
 *
 * @stable ICU 3.8
 */
@Override
protected Object readResolve() throws InvalidObjectException {
    if (this.getClass() != MessageFormat.Field.class) {
        throw new InvalidObjectException(
            "A subclass of MessageFormat.Field must implement readResolve.");
    }
    if (this.getName().equals(ARGUMENT.getName())) {
        return ARGUMENT;
    } else {
        throw new InvalidObjectException("Unknown attribute name.");
    }
}
 
Example 33
Project: BetterRandom   File: BaseRandom.java   View source code 5 votes vote down vote up
/**
 * Used to deserialize a subclass instance that wasn't a subclass instance when it was serialized.
 * Since that means we can't deserialize our seed, we generate a new one with the {@link
 * DefaultSeedGenerator}.
 * @throws InvalidObjectException if the {@link DefaultSeedGenerator} fails.
 */
@SuppressWarnings("OverriddenMethodCallDuringObjectConstruction") private void readObjectNoData()
    throws InvalidObjectException {
  LOG.warn("BaseRandom.readObjectNoData() invoked; using DefaultSeedGenerator");
  try {
    fallbackSetSeed();
  } catch (final RuntimeException e) {
    throw (InvalidObjectException) (new InvalidObjectException(
        "Failed to deserialize or generate a seed").initCause(e.getCause()));
  }
  initTransientFields();
  setSeedInternal(seed);
}
 
Example 34
Project: jdk8u-jdk   File: AttributedCharacterIterator.java   View source code 5 votes vote down vote up
/**
 * Resolves instances being deserialized to the predefined constants.
 *
 * @return the resolved {@code Attribute} object
 * @throws InvalidObjectException if the object to resolve is not
 *                                an instance of {@code Attribute}
 */
protected Object readResolve() throws InvalidObjectException {
    if (this.getClass() != Attribute.class) {
        throw new InvalidObjectException("subclass didn't correctly implement readResolve");
    }

    Attribute instance = instanceMap.get(getName());
    if (instance != null) {
        return instance;
    } else {
        throw new InvalidObjectException("unknown attribute name");
    }
}
 
Example 35
Project: CommonInformationSpace   File: MLPConnectorCoreExt.java   View source code 5 votes vote down vote up
/**
 * This method receives an Object (MLP as String) and forwards it to the CIS CIS Core
 * 
 * @param msg the MLP String
 * @throws InvalidObjectException when the String is not valid MLP
 */
public void notify(Object msg, Map<DEParameters, String> deParameters, boolean dontEnvelope) throws InvalidObjectException {
	log.info("--> notify");
	
	String msgStr = null;
	if (msg instanceof String) {
		msgStr = (String)msg;
		if (msgStr.startsWith("<?xml version")) {
			int idx = msgStr.indexOf("<svc_");
			if (idx != -1) {
				msgStr = msgStr.substring(idx);
			}
		}
	} else {
		throw new InvalidObjectException("Given Object is no valid MLP Message!");
	}
	
	try {
		CISXMLContent xmlCont = new CISXMLContent();
		xmlCont.setEmbeddedXMLContent(msgStr);
		restSender.notify(CoreConstants.MSGTYPE_MLP, xmlCont, null, false);
	} catch (CISCommunicationException | CISInvalidXMLObject e) {
		log.error("notify: " + e);
	}
	
	log.info("notify -->");
}
 
Example 36
Project: OpenJSharp   File: NumberFormat.java   View source code 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 NumberFormat.Field constant
 */
@Override
protected Object readResolve() throws InvalidObjectException {
    if (this.getClass() != NumberFormat.Field.class) {
        throw new InvalidObjectException("subclass didn't correctly implement readResolve");
    }

    Object instance = instanceMap.get(getName());
    if (instance != null) {
        return instance;
    } else {
        throw new InvalidObjectException("unknown attribute name");
    }
}
 
Example 37
Project: OpenJSharp   File: WeekFields.java   View source code 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 38
Project: CommonInformationSpace   File: MLPConnectorCoreExt.java   View source code 5 votes vote down vote up
/**
 * This message is called by the ConnectorCore when a message was receive. It will be translatet to the Application
 * representation and the translatet message if send via the registered callback to the application.
 * 
 * @param msg
 * @throws InvalidObjectException
 */
public void msgReceived(CISPayload payload) throws InvalidObjectException {
	log.info("--> messageReceived");
	
	// create and forward the message to the connector
	if (AppCallbackHandlerImpl.getInstance().getCallback(CoreConstants.MSGTYPE_MLP) != null) {
		AppCallbackHandlerImpl.getInstance().getCallback(CoreConstants.MSGTYPE_MLP).msgReceived(payload);
	}
	
	log.info("messageReceived -->");
}
 
Example 39
Project: jdk8u-jdk   File: DefaultMXBeanMappingFactory.java   View source code 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 40
Project: SimpleUILauncher   File: RestoreDbTask.java   View source code 5 votes vote down vote up
/**
 * Returns the profile id used in the favorites table of the provided db.
 */
protected long getDefaultProfileId(SQLiteDatabase db) throws Exception {
    try (Cursor c = db.rawQuery("PRAGMA table_info (favorites)", null)){
        int nameIndex = c.getColumnIndex(INFO_COLUMN_NAME);
        while (c.moveToNext()) {
            if (Favorites.PROFILE_ID.equals(c.getString(nameIndex))) {
                return c.getLong(c.getColumnIndex(INFO_COLUMN_DEFAULT_VALUE));
            }
        }
        throw new InvalidObjectException("Table does not have a profile id column");
    }
}