687 ClassLoader latestLoader = latestUserDefinedLoader(); |
687 ClassLoader latestLoader = latestUserDefinedLoader(); |
688 ClassLoader nonPublicLoader = null; |
688 ClassLoader nonPublicLoader = null; |
689 boolean hasNonPublicInterface = false; |
689 boolean hasNonPublicInterface = false; |
690 |
690 |
691 // define proxy in class loader of non-public interface(s), if any |
691 // define proxy in class loader of non-public interface(s), if any |
692 Class[] classObjs = new Class[interfaces.length]; |
692 Class<?>[] classObjs = new Class<?>[interfaces.length]; |
693 for (int i = 0; i < interfaces.length; i++) { |
693 for (int i = 0; i < interfaces.length; i++) { |
694 Class cl = Class.forName(interfaces[i], false, latestLoader); |
694 Class<?> cl = Class.forName(interfaces[i], false, latestLoader); |
695 if ((cl.getModifiers() & Modifier.PUBLIC) == 0) { |
695 if ((cl.getModifiers() & Modifier.PUBLIC) == 0) { |
696 if (hasNonPublicInterface) { |
696 if (hasNonPublicInterface) { |
697 if (nonPublicLoader != cl.getClassLoader()) { |
697 if (nonPublicLoader != cl.getClassLoader()) { |
698 throw new IllegalAccessError( |
698 throw new IllegalAccessError( |
699 "conflicting non-public interface class loaders"); |
699 "conflicting non-public interface class loaders"); |
1227 * without violating security constraints: the subclass must not override |
1227 * without violating security constraints: the subclass must not override |
1228 * security-sensitive non-final methods, or else the |
1228 * security-sensitive non-final methods, or else the |
1229 * "enableSubclassImplementation" SerializablePermission is checked. |
1229 * "enableSubclassImplementation" SerializablePermission is checked. |
1230 */ |
1230 */ |
1231 private void verifySubclass() { |
1231 private void verifySubclass() { |
1232 Class cl = getClass(); |
1232 Class<?> cl = getClass(); |
1233 if (cl == ObjectInputStream.class) { |
1233 if (cl == ObjectInputStream.class) { |
1234 return; |
1234 return; |
1235 } |
1235 } |
1236 SecurityManager sm = System.getSecurityManager(); |
1236 SecurityManager sm = System.getSecurityManager(); |
1237 if (sm == null) { |
1237 if (sm == null) { |
1471 * Reads in and returns class object. Sets passHandle to class object's |
1471 * Reads in and returns class object. Sets passHandle to class object's |
1472 * assigned handle. Returns null if class is unresolvable (in which case a |
1472 * assigned handle. Returns null if class is unresolvable (in which case a |
1473 * ClassNotFoundException will be associated with the class' handle in the |
1473 * ClassNotFoundException will be associated with the class' handle in the |
1474 * handle table). |
1474 * handle table). |
1475 */ |
1475 */ |
1476 private Class readClass(boolean unshared) throws IOException { |
1476 private Class<?> readClass(boolean unshared) throws IOException { |
1477 if (bin.readByte() != TC_CLASS) { |
1477 if (bin.readByte() != TC_CLASS) { |
1478 throw new InternalError(); |
1478 throw new InternalError(); |
1479 } |
1479 } |
1480 ObjectStreamClass desc = readClassDesc(false); |
1480 ObjectStreamClass desc = readClassDesc(false); |
1481 Class cl = desc.forClass(); |
1481 Class<?> cl = desc.forClass(); |
1482 passHandle = handles.assign(unshared ? unsharedMarker : cl); |
1482 passHandle = handles.assign(unshared ? unsharedMarker : cl); |
1483 |
1483 |
1484 ClassNotFoundException resolveEx = desc.getResolveException(); |
1484 ClassNotFoundException resolveEx = desc.getResolveException(); |
1485 if (resolveEx != null) { |
1485 if (resolveEx != null) { |
1486 handles.markException(passHandle, resolveEx); |
1486 handles.markException(passHandle, resolveEx); |
1540 String[] ifaces = new String[numIfaces]; |
1540 String[] ifaces = new String[numIfaces]; |
1541 for (int i = 0; i < numIfaces; i++) { |
1541 for (int i = 0; i < numIfaces; i++) { |
1542 ifaces[i] = bin.readUTF(); |
1542 ifaces[i] = bin.readUTF(); |
1543 } |
1543 } |
1544 |
1544 |
1545 Class cl = null; |
1545 Class<?> cl = null; |
1546 ClassNotFoundException resolveEx = null; |
1546 ClassNotFoundException resolveEx = null; |
1547 bin.setBlockDataMode(true); |
1547 bin.setBlockDataMode(true); |
1548 try { |
1548 try { |
1549 if ((cl = resolveProxyClass(ifaces)) == null) { |
1549 if ((cl = resolveProxyClass(ifaces)) == null) { |
1550 resolveEx = new ClassNotFoundException("null class"); |
1550 resolveEx = new ClassNotFoundException("null class"); |
1584 } catch (ClassNotFoundException ex) { |
1584 } catch (ClassNotFoundException ex) { |
1585 throw (IOException) new InvalidClassException( |
1585 throw (IOException) new InvalidClassException( |
1586 "failed to read class descriptor").initCause(ex); |
1586 "failed to read class descriptor").initCause(ex); |
1587 } |
1587 } |
1588 |
1588 |
1589 Class cl = null; |
1589 Class<?> cl = null; |
1590 ClassNotFoundException resolveEx = null; |
1590 ClassNotFoundException resolveEx = null; |
1591 bin.setBlockDataMode(true); |
1591 bin.setBlockDataMode(true); |
1592 try { |
1592 try { |
1593 if ((cl = resolveClass(readDesc)) == null) { |
1593 if ((cl = resolveClass(readDesc)) == null) { |
1594 resolveEx = new ClassNotFoundException("null class"); |
1594 resolveEx = new ClassNotFoundException("null class"); |
1641 |
1641 |
1642 ObjectStreamClass desc = readClassDesc(false); |
1642 ObjectStreamClass desc = readClassDesc(false); |
1643 int len = bin.readInt(); |
1643 int len = bin.readInt(); |
1644 |
1644 |
1645 Object array = null; |
1645 Object array = null; |
1646 Class cl, ccl = null; |
1646 Class<?> cl, ccl = null; |
1647 if ((cl = desc.forClass()) != null) { |
1647 if ((cl = desc.forClass()) != null) { |
1648 ccl = cl.getComponentType(); |
1648 ccl = cl.getComponentType(); |
1649 array = Array.newInstance(ccl, len); |
1649 array = Array.newInstance(ccl, len); |
1650 } |
1650 } |
1651 |
1651 |
1694 |
1694 |
1695 /** |
1695 /** |
1696 * Reads in and returns enum constant, or null if enum type is |
1696 * Reads in and returns enum constant, or null if enum type is |
1697 * unresolvable. Sets passHandle to enum constant's assigned handle. |
1697 * unresolvable. Sets passHandle to enum constant's assigned handle. |
1698 */ |
1698 */ |
1699 private Enum readEnum(boolean unshared) throws IOException { |
1699 private Enum<?> readEnum(boolean unshared) throws IOException { |
1700 if (bin.readByte() != TC_ENUM) { |
1700 if (bin.readByte() != TC_ENUM) { |
1701 throw new InternalError(); |
1701 throw new InternalError(); |
1702 } |
1702 } |
1703 |
1703 |
1704 ObjectStreamClass desc = readClassDesc(false); |
1704 ObjectStreamClass desc = readClassDesc(false); |
1711 if (resolveEx != null) { |
1711 if (resolveEx != null) { |
1712 handles.markException(enumHandle, resolveEx); |
1712 handles.markException(enumHandle, resolveEx); |
1713 } |
1713 } |
1714 |
1714 |
1715 String name = readString(false); |
1715 String name = readString(false); |
1716 Enum en = null; |
1716 Enum<?> result = null; |
1717 Class cl = desc.forClass(); |
1717 Class<?> cl = desc.forClass(); |
1718 if (cl != null) { |
1718 if (cl != null) { |
1719 try { |
1719 try { |
1720 en = Enum.valueOf(cl, name); |
1720 @SuppressWarnings("unchecked") |
|
1721 Enum<?> en = Enum.valueOf((Class)cl, name); |
|
1722 result = en; |
1721 } catch (IllegalArgumentException ex) { |
1723 } catch (IllegalArgumentException ex) { |
1722 throw (IOException) new InvalidObjectException( |
1724 throw (IOException) new InvalidObjectException( |
1723 "enum constant " + name + " does not exist in " + |
1725 "enum constant " + name + " does not exist in " + |
1724 cl).initCause(ex); |
1726 cl).initCause(ex); |
1725 } |
1727 } |
1726 if (!unshared) { |
1728 if (!unshared) { |
1727 handles.setObject(enumHandle, en); |
1729 handles.setObject(enumHandle, result); |
1728 } |
1730 } |
1729 } |
1731 } |
1730 |
1732 |
1731 handles.finish(enumHandle); |
1733 handles.finish(enumHandle); |
1732 passHandle = enumHandle; |
1734 passHandle = enumHandle; |
1733 return en; |
1735 return result; |
1734 } |
1736 } |
1735 |
1737 |
1736 /** |
1738 /** |
1737 * Reads and returns "ordinary" (i.e., not a String, Class, |
1739 * Reads and returns "ordinary" (i.e., not a String, Class, |
1738 * ObjectStreamClass, array, or enum constant) object, or null if object's |
1740 * ObjectStreamClass, array, or enum constant) object, or null if object's |
1939 */ |
1941 */ |
1940 private void defaultReadFields(Object obj, ObjectStreamClass desc) |
1942 private void defaultReadFields(Object obj, ObjectStreamClass desc) |
1941 throws IOException |
1943 throws IOException |
1942 { |
1944 { |
1943 // REMIND: is isInstance check necessary? |
1945 // REMIND: is isInstance check necessary? |
1944 Class cl = desc.forClass(); |
1946 Class<?> cl = desc.forClass(); |
1945 if (cl != null && obj != null && !cl.isInstance(obj)) { |
1947 if (cl != null && obj != null && !cl.isInstance(obj)) { |
1946 throw new ClassCastException(); |
1948 throw new ClassCastException(); |
1947 } |
1949 } |
1948 |
1950 |
1949 int primDataSize = desc.getPrimDataSize(); |
1951 int primDataSize = desc.getPrimDataSize(); |
2138 * If no matching field is found in the (incoming) class |
2140 * If no matching field is found in the (incoming) class |
2139 * descriptor but a matching field is present in the associated local |
2141 * descriptor but a matching field is present in the associated local |
2140 * class descriptor, returns -1. Throws IllegalArgumentException if |
2142 * class descriptor, returns -1. Throws IllegalArgumentException if |
2141 * neither incoming nor local class descriptor contains a match. |
2143 * neither incoming nor local class descriptor contains a match. |
2142 */ |
2144 */ |
2143 private int getFieldOffset(String name, Class type) { |
2145 private int getFieldOffset(String name, Class<?> type) { |
2144 ObjectStreamField field = desc.getField(name, type); |
2146 ObjectStreamField field = desc.getField(name, type); |
2145 if (field != null) { |
2147 if (field != null) { |
2146 return field.getOffset(); |
2148 return field.getOffset(); |
2147 } else if (desc.getLocalDesc().getField(name, type) != null) { |
2149 } else if (desc.getLocalDesc().getField(name, type) != null) { |
2148 return -1; |
2150 return -1; |
2836 |
2838 |
2837 public String readUTF() throws IOException { |
2839 public String readUTF() throws IOException { |
2838 return readUTFBody(readUnsignedShort()); |
2840 return readUTFBody(readUnsignedShort()); |
2839 } |
2841 } |
2840 |
2842 |
|
2843 @SuppressWarnings("deprecation") |
2841 public String readLine() throws IOException { |
2844 public String readLine() throws IOException { |
2842 return din.readLine(); // deprecated, not worth optimizing |
2845 return din.readLine(); // deprecated, not worth optimizing |
2843 } |
2846 } |
2844 |
2847 |
2845 /* -------------- primitive data array input methods --------------- */ |
2848 /* -------------- primitive data array input methods --------------- */ |