Java Code Examples for java.io.ObjectInputStream#GetField

The following examples show how to use java.io.ObjectInputStream#GetField . 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: RoleResult.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes a {@link RoleResult} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    ObjectInputStream.GetField fields = in.readFields();
    roleList = (RoleList) fields.get("myRoleList", null);
    if (fields.defaulted("myRoleList"))
    {
      throw new NullPointerException("myRoleList");
    }
    unresolvedRoleList = (RoleUnresolvedList) fields.get("myRoleUnresList", null);
    if (fields.defaulted("myRoleUnresList"))
    {
      throw new NullPointerException("myRoleUnresList");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 2
Source File: VetoableChangeSupport.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    this.map = new VetoableChangeListenerMap();

    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Hashtable<String, VetoableChangeSupport> children = (Hashtable<String, VetoableChangeSupport>)fields.get("children", null);
    this.source = fields.get("source", null);
    fields.get("vetoableChangeSupportSerializedDataVersion", 2);

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
        this.map.add(null, (VetoableChangeListener)listenerOrNull);
    }
    if (children != null) {
        for (Entry<String, VetoableChangeSupport> entry : children.entrySet()) {
            for (VetoableChangeListener listener : entry.getValue().getVetoableChangeListeners()) {
                this.map.add(entry.getKey(), listener);
            }
        }
    }
}
 
Example 3
Source File: GetFieldTest.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  ObjectInputStream.GetField fields = in.readFields();
  if (!fields.defaulted("blargh")) {
    throw new Error();
  }
  try {
    fields.defaulted("nonexistant");
    throw new Error();
  } catch (IllegalArgumentException ex) {
  }
  if ((fields.get("z", false) != true)
          || (fields.get("b", (byte) 0) != 5)
          || (fields.get("c", '0') != '5')
          || (fields.get("s", (short) 0) != 5)
          || (fields.get("i", 0) != 5)
          || (fields.get("j", 0l) != 5)
          || (fields.get("f", 0.0f) != 5.0f)
          || (fields.get("d", 0.0) != 5.0)
          || (!fields.get("str", null).equals("5"))) {
    throw new Error();
  }
}
 
Example 4
Source File: PropertyChangeSupport.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    this.map = new PropertyChangeListenerMap();

    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
    this.source = fields.get("source", null);
    fields.get("propertyChangeSupportSerializedDataVersion", 2);

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
        this.map.add(null, (PropertyChangeListener)listenerOrNull);
    }
    if (children != null) {
        for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
            for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
                this.map.add(entry.getKey(), listener);
            }
        }
    }
}
 
Example 5
Source File: Role.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes a {@link Role} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    ObjectInputStream.GetField fields = in.readFields();
    name = (String) fields.get("myName", null);
    if (fields.defaulted("myName"))
    {
      throw new NullPointerException("myName");
    }
    objectNameList = cast(fields.get("myObjNameList", null));
    if (fields.defaulted("myObjNameList"))
    {
      throw new NullPointerException("myObjNameList");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 6
Source File: Locale.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Deserializes this <code>Locale</code>.
 * @param in the <code>ObjectInputStream</code> to read
 * @throws IOException
 * @throws ClassNotFoundException
 * @throws IllformedLocaleException
 * @since 1.7
 */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    ObjectInputStream.GetField fields = in.readFields();
    String language = (String)fields.get("language", "");
    String script = (String)fields.get("script", "");
    String country = (String)fields.get("country", "");
    String variant = (String)fields.get("variant", "");
    String extStr = (String)fields.get("extensions", "");
    baseLocale = BaseLocale.getInstance(convertOldISOCodes(language), script, country, variant);
    if (extStr.length() > 0) {
        try {
            InternalLocaleBuilder bldr = new InternalLocaleBuilder();
            bldr.setExtensions(extStr);
            localeExtensions = bldr.getLocaleExtensions();
        } catch (LocaleSyntaxException e) {
            throw new IllformedLocaleException(e.getMessage());
        }
    } else {
        localeExtensions = null;
    }
}
 
Example 7
Source File: PropertyPermission.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get all_allowed
    all_allowed = gfields.get("all_allowed", false);

    // Get permissions
    @SuppressWarnings("unchecked")
    Hashtable<String, PropertyPermission> permissions =
        (Hashtable<String, PropertyPermission>)gfields.get("permissions", null);
    perms = new HashMap<>(permissions.size()*2);
    perms.putAll(permissions);
}
 
Example 8
Source File: PropertyChangeSupport.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    this.map = new PropertyChangeListenerMap();

    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Hashtable<String, PropertyChangeSupport> children = (Hashtable<String, PropertyChangeSupport>) fields.get("children", null);
    this.source = fields.get("source", null);
    fields.get("propertyChangeSupportSerializedDataVersion", 2);

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
        this.map.add(null, (PropertyChangeListener)listenerOrNull);
    }
    if (children != null) {
        for (Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
            for (PropertyChangeListener listener : entry.getValue().getPropertyChangeListeners()) {
                this.map.add(entry.getKey(), listener);
            }
        }
    }
}
 
Example 9
Source File: MBeanServerNotificationFilter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deserializes an {@link MBeanServerNotificationFilter} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    ObjectInputStream.GetField fields = in.readFields();
    selectedNames = cast(fields.get("mySelectObjNameList", null));
    if (fields.defaulted("mySelectObjNameList"))
    {
      throw new NullPointerException("mySelectObjNameList");
    }
    deselectedNames = cast(fields.get("myDeselectObjNameList", null));
    if (fields.defaulted("myDeselectObjNameList"))
    {
      throw new NullPointerException("myDeselectObjNameList");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 10
Source File: UnresolvedPermissionCollection.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get permissions
    Hashtable<String, Vector<UnresolvedPermission>> permissions =
            (Hashtable<String, Vector<UnresolvedPermission>>)gfields.get("permissions", null);
    perms = new HashMap<String, List<UnresolvedPermission>>(permissions.size()*2);

    // Convert each entry (Vector) into a List
    Set<Map.Entry<String, Vector<UnresolvedPermission>>> set = permissions.entrySet();
    for (Map.Entry<String, Vector<UnresolvedPermission>> e : set) {
        // Convert Vector into ArrayList
        Vector<UnresolvedPermission> vec = e.getValue();
        List<UnresolvedPermission> list = new ArrayList<>(vec.size());
        list.addAll(vec);

        // Add to Hashtable being serialized
        perms.put(e.getKey(), list);
    }
}
 
Example 11
Source File: InputStreamHook.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public ObjectInputStream.GetField readFields()
    throws IOException, ClassNotFoundException, NotActiveException {

    HashMap fieldValueMap = new HashMap();

    // We were treating readFields same as defaultReadObject. It is
    // incorrect if the state is readOptionalData. If this line
    // is uncommented, it will throw a stream corrupted exception.
    // _REVISIT_: The ideal fix would be to add a new state. In
    // writeObject user may do one of the following
    // 1. Call defaultWriteObject()
    // 2. Put out optional fields
    // 3. Call writeFields
    // We have the state defined for (1) and (2) but not for (3), so
    // we should ideally introduce a new state for 3 and have the
    // beginDefaultReadObject do nothing.
    //readObjectState.beginDefaultReadObject(this);

    readFields(fieldValueMap);

    readObjectState.endDefaultReadObject(this);

    return new HookGetFields(fieldValueMap);
}
 
Example 12
Source File: ScrollPane.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Reads default serializable fields to stream.
     * @exception HeadlessException if
     * <code>GraphicsEnvironment.isHeadless()</code> returns
     * <code>true</code>
     * @see java.awt.GraphicsEnvironment#isHeadless
     */
    private void readObject(ObjectInputStream s)
        throws ClassNotFoundException, IOException, HeadlessException
    {
        GraphicsEnvironment.checkHeadless();
        // 4352819: Gotcha!  Cannot use s.defaultReadObject here and
        // then continue with reading optional data.  Use GetField instead.
        ObjectInputStream.GetField f = s.readFields();

        // Old fields
        scrollbarDisplayPolicy = f.get("scrollbarDisplayPolicy",
                                       SCROLLBARS_AS_NEEDED);
        hAdjustable = (ScrollPaneAdjustable)f.get("hAdjustable", null);
        vAdjustable = (ScrollPaneAdjustable)f.get("vAdjustable", null);

        // Since 1.4
        wheelScrollingEnabled = f.get("wheelScrollingEnabled",
                                      defaultWheelScroll);

//      // Note to future maintainers
//      if (f.defaulted("wheelScrollingEnabled")) {
//          // We are reading pre-1.4 stream that doesn't have
//          // optional data, not even the TC_ENDBLOCKDATA marker.
//          // Reading anything after this point is unsafe as we will
//          // read unrelated objects further down the stream (4352819).
//      }
//      else {
//          // Reading data from 1.4 or later, it's ok to try to read
//          // optional data as OptionalDataException with eof == true
//          // will be correctly reported
//      }
    }
 
Example 13
Source File: ModelMBeanInfoSupport.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
    if (compat) {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
        modelMBeanDescriptor =
                (Descriptor) fields.get("modelMBeanDescriptor", null);
        if (fields.defaulted("modelMBeanDescriptor")) {
            throw new NullPointerException("modelMBeanDescriptor");
        }
        modelMBeanAttributes =
                (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
        if (fields.defaulted("mmbAttributes")) {
            throw new NullPointerException("mmbAttributes");
        }
        modelMBeanConstructors =
                (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
        if (fields.defaulted("mmbConstructors")) {
            throw new NullPointerException("mmbConstructors");
        }
        modelMBeanNotifications =
                (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
        if (fields.defaulted("mmbNotifications")) {
            throw new NullPointerException("mmbNotifications");
        }
        modelMBeanOperations =
                (MBeanOperationInfo[]) fields.get("mmbOperations", null);
        if (fields.defaulted("mmbOperations")) {
            throw new NullPointerException("mmbOperations");
        }
    } else {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
    }
}
 
Example 14
Source File: RoleUnresolved.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
/**
 * Deserializes a {@link RoleUnresolved} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    ObjectInputStream.GetField fields = in.readFields();
    roleName = (String) fields.get("myRoleName", null);
    if (fields.defaulted("myRoleName"))
    {
      throw new NullPointerException("myRoleName");
    }
    roleValue = cast(fields.get("myRoleValue", null));
    if (fields.defaulted("myRoleValue"))
    {
      throw new NullPointerException("myRoleValue");
    }
    problemType = fields.get("myPbType", 0);
    if (fields.defaulted("myPbType"))
    {
      throw new NullPointerException("myPbType");
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 15
Source File: Token.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
                    throws IOException, ClassNotFoundException {
    // We have to read serialized fields first.
    ObjectInputStream.GetField gf = in.readFields();
    Vector<Token> vChildren = (Vector<Token>)gf.get("children", null);

    //convert Vector back to List
    if (vChildren != null) children = new ArrayList<>(vChildren);
}
 
Example 16
Source File: ServicePermission.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get the one we want
    Vector<Permission> permissions =
            (Vector<Permission>)gfields.get("permissions", null);
    perms = new ArrayList<Permission>(permissions.size());
    perms.addAll(permissions);
}
 
Example 17
Source File: UnresolvedPermissionCollection.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get permissions
    @SuppressWarnings("unchecked")
    // writeObject writes a Hashtable<String, Vector<UnresolvedPermission>>
    // for the permissions key, so this cast is safe, unless the data is corrupt.
    Hashtable<String, Vector<UnresolvedPermission>> permissions =
            (Hashtable<String, Vector<UnresolvedPermission>>)
            gfields.get("permissions", null);
    perms = new HashMap<String, List<UnresolvedPermission>>(permissions.size()*2);

    // Convert each entry (Vector) into a List
    Set<Map.Entry<String, Vector<UnresolvedPermission>>> set = permissions.entrySet();
    for (Map.Entry<String, Vector<UnresolvedPermission>> e : set) {
        // Convert Vector into ArrayList
        Vector<UnresolvedPermission> vec = e.getValue();
        List<UnresolvedPermission> list = new ArrayList<>(vec.size());
        list.addAll(vec);

        // Add to Hashtable being serialized
        perms.put(e.getKey(), list);
    }
}
 
Example 18
Source File: NumericValueExp.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Deserializes a {@link NumericValueExp} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    double doubleVal;
    long longVal;
    boolean isLong;
    ObjectInputStream.GetField fields = in.readFields();
    doubleVal = fields.get("doubleVal", (double)0);
    if (fields.defaulted("doubleVal"))
    {
      throw new NullPointerException("doubleVal");
    }
    longVal = fields.get("longVal", (long)0);
    if (fields.defaulted("longVal"))
    {
      throw new NullPointerException("longVal");
    }
    isLong = fields.get("valIsLong", false);
    if (fields.defaulted("valIsLong"))
    {
      throw new NullPointerException("valIsLong");
    }
    if (isLong)
    {
      this.val = longVal;
    }
    else
    {
      this.val = doubleVal;
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}
 
Example 19
Source File: AnnotationInvocationHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void readObject(java.io.ObjectInputStream s)
    throws java.io.IOException, ClassNotFoundException {
    ObjectInputStream.GetField fields = s.readFields();

    @SuppressWarnings("unchecked")
    Class<? extends Annotation> t = (Class<? extends Annotation>)fields.get("type", null);
    @SuppressWarnings("unchecked")
    Map<String, Object> streamVals = (Map<String, Object>)fields.get("memberValues", null);

    // Check to make sure that types have not evolved incompatibly

    AnnotationType annotationType = null;
    try {
        annotationType = AnnotationType.getInstance(t);
    } catch(IllegalArgumentException e) {
        // Class is no longer an annotation type; time to punch out
        throw new java.io.InvalidObjectException("Non-annotation type in annotation serial stream");
    }

    Map<String, Class<?>> memberTypes = annotationType.memberTypes();
    // consistent with runtime Map type
    Map<String, Object> mv = new LinkedHashMap<>();

    // If there are annotation members without values, that
    // situation is handled by the invoke method.
    for (Map.Entry<String, Object> memberValue : streamVals.entrySet()) {
        String name = memberValue.getKey();
        Object value = null;
        Class<?> memberType = memberTypes.get(name);
        if (memberType != null) {  // i.e. member still exists
            value = memberValue.getValue();
            if (!(memberType.isInstance(value) ||
                  value instanceof ExceptionProxy)) {
                value = new AnnotationTypeMismatchExceptionProxy(
                        value.getClass() + "[" + value + "]").setMember(
                            annotationType.members().get(name));
            }
        }
        mv.put(name, value);
    }

    UnsafeAccessor.setType(this, t);
    UnsafeAccessor.setMemberValues(this, mv);
}
 
Example 20
Source File: NumericValueExp.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Deserializes a {@link NumericValueExp} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException {
  if (compat)
  {
    // Read an object serialized in the old serial form
    //
    double doubleVal;
    long longVal;
    boolean isLong;
    ObjectInputStream.GetField fields = in.readFields();
    doubleVal = fields.get("doubleVal", (double)0);
    if (fields.defaulted("doubleVal"))
    {
      throw new NullPointerException("doubleVal");
    }
    longVal = fields.get("longVal", (long)0);
    if (fields.defaulted("longVal"))
    {
      throw new NullPointerException("longVal");
    }
    isLong = fields.get("valIsLong", false);
    if (fields.defaulted("valIsLong"))
    {
      throw new NullPointerException("valIsLong");
    }
    if (isLong)
    {
      this.val = longVal;
    }
    else
    {
      this.val = doubleVal;
    }
  }
  else
  {
    // Read an object serialized in the new serial form
    //
    in.defaultReadObject();
  }
}