java类java.io.InvalidObjectException的实例源码

ImmutableListMultimap.java 文件源码 项目:googles-monorepo-demo 阅读 16 收藏 0 点赞 0 评论 0
@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);
}
MessageFormat.java 文件源码 项目:fitnotifications 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 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.");
    }
}
BaseRandom.java 文件源码 项目:BetterRandom 阅读 29 收藏 0 点赞 0 评论 0
/**
 * 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);
}
AttributedCharacterIterator.java 文件源码 项目:jdk8u-jdk 阅读 15 收藏 0 点赞 0 评论 0
/**
 * 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");
    }
}
MLPConnectorCoreExt.java 文件源码 项目:CommonInformationSpace 阅读 15 收藏 0 点赞 0 评论 0
/**
 * 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 -->");
}
NumberFormat.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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");
    }
}
WeekFields.java 文件源码 项目:OpenJSharp 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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());
    }
}
MLPConnectorCoreExt.java 文件源码 项目:CommonInformationSpace 阅读 15 收藏 0 点赞 0 评论 0
/**
 * 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 -->");
}
RestoreDbTask.java 文件源码 项目:FlickLauncher 阅读 15 收藏 0 点赞 0 评论 0
/**
 * 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");
    }
}
DefaultMXBeanMappingFactory.java 文件源码 项目:jdk8u-jdk 阅读 30 收藏 0 点赞 0 评论 0
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);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号