java.io.InvalidClassException Java Examples

The following examples show how to use java.io.InvalidClassException. 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 Project: jdk8u_jdk   Author: JetBrains   File: CheckArrayTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test SharedSecrets checkArray with unmodified ObjectInputStream.
 */
@Test(dataProvider = "Patterns")
public void normalOIS(String pattern, int arraySize, Object[] array) throws IOException {
    ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);
    byte[] bytes = SerialFilterTest.writeObjects(array);
    try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
         ObjectInputStream ois = new ObjectInputStream(bais)) {
        // Check the arraysize against the filter
        try {
            ObjectInputFilter.Config.setObjectInputFilter(ois, filter);
            SharedSecrets.getJavaOISAccess()
                    .checkArray(ois, array.getClass(), arraySize);
            Assert.assertTrue(array.length >= arraySize,
                    "Should have thrown InvalidClassException due to array size");
        } catch (InvalidClassException ice) {
            Assert.assertFalse(array.length > arraySize,
                    "Should NOT have thrown InvalidClassException due to array size");
        }
    }
}
 
Example #2
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: IIOPInputStream.java    License: Apache License 2.0 6 votes vote down vote up
private void skipCustomUsingFVD(ValueMember[] fields,
                                com.sun.org.omg.SendingContext.CodeBase sender)
                                throws InvalidClassException, StreamCorruptedException,
                                       ClassNotFoundException, IOException
{
    readFormatVersion();
    boolean calledDefaultWriteObject = readBoolean();

    if (calledDefaultWriteObject)
        throwAwayData(fields, sender);

    if (getStreamFormatVersion() == 2) {

        ((ValueInputStream)getOrbStream()).start_value();
        ((ValueInputStream)getOrbStream()).end_value();
    }
}
 
Example #3
Source Project: SerialKiller   Author: ikkisoft   File: SerialKillerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected = InvalidClassException.class)
public void testThreadIssue() throws Exception {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();

    try (ObjectOutputStream stream = new ObjectOutputStream(bytes)) {
        stream.writeObject(42);
    }

    try (ObjectInputStream stream = new SerialKiller(new ByteArrayInputStream(bytes.toByteArray()), "src/test/resources/blacklist-all.conf")) {
        // Create a dummy SK with different config
        new SerialKiller(new ByteArrayInputStream(bytes.toByteArray()), "src/test/resources/whitelist-all.conf");

        stream.readObject();
        fail("All should be blacklisted");
    }
}
 
Example #4
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TestSerialization.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void testReadWrite() {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        testWrite(oos);
        oos.flush();
        oos.close();
        byte buf[] = baos.toByteArray();
        ByteArrayInputStream bais = new ByteArrayInputStream(buf);
        ObjectInputStream ois = new ObjectInputStream(bais);
        testRead(ois, true);
    } catch (InvalidClassException ice) {
        throw new RuntimeException("Object read failed from loopback");
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("IOException testing loopback");
    }
}
 
Example #5
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CheckArrayTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test SharedSecrets checkArray with an ObjectInputStream subclassed to
 * handle all input stream functions.
 */
@Test(dataProvider = "Patterns")
public void subclassedOIS(String pattern, int arraySize, Object[] array) throws IOException {
    byte[] bytes = SerialFilterTest.writeObjects(array);
    try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
         ObjectInputStream ois = new MyInputStream(bais)) {
        // Check the arraysize against the filter
        ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);
        ObjectInputFilter.Config.setObjectInputFilter(ois, filter);
        SharedSecrets.getJavaOISAccess()
                .checkArray(ois, array.getClass(), arraySize);
        Assert.assertTrue(array.length >= arraySize,
                "Should have thrown InvalidClassException due to array size");
    } catch (InvalidClassException ice) {
        Assert.assertFalse(array.length > arraySize,
                "Should NOT have thrown InvalidClassException due to array size");
    }
}
 
Example #6
Source Project: desugar_jdk_libs   Author: google   File: Ser.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static void writeInternal(byte type, Object object, DataOutput out) throws IOException {
    out.writeByte(type);
    switch (type) {
        case ZRULES:
            ((ZoneRules) object).writeExternal(out);
            break;
        case ZOT:
            ((ZoneOffsetTransition) object).writeExternal(out);
            break;
        case ZOTRULE:
            ((ZoneOffsetTransitionRule) object).writeExternal(out);
            break;
        case TZRULES:
            ((ZoneRules) object).writeExternalTimeZone(out);
            break;
        default:
            throw new InvalidClassException("Unknown serialized type");
    }
}
 
Example #7
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: IIOPInputStream.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void skipCustomUsingFVD(ValueMember[] fields,
                                com.sun.org.omg.SendingContext.CodeBase sender)
                                throws InvalidClassException, StreamCorruptedException,
                                       ClassNotFoundException, IOException
{
    readFormatVersion();
    boolean calledDefaultWriteObject = readBoolean();

    if (calledDefaultWriteObject)
        throwAwayData(fields, sender);

    if (getStreamFormatVersion() == 2) {

        ((ValueInputStream)getOrbStream()).start_value();
        ((ValueInputStream)getOrbStream()).end_value();
    }
}
 
Example #8
Source Project: TencentKona-8   Author: Tencent   File: GlobalFilterTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
     * Serialize and deserialize an object using the default process-wide filter
     * and check allowed or reject.
     *
     * @param pattern the pattern
     * @param object the test object
     * @param allowed the expected result from ObjectInputStream (exception or not)
     */
    static void testGlobalPattern(String pattern, Object object, boolean allowed) {
        try {
//            System.out.printf("global %s pattern: %s, obj: %s%n", (allowed ? "allowed" : "not allowed"), pattern, object);
            byte[] bytes = SerialFilterTest.writeObjects(object);
            try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
                 ObjectInputStream ois = new ObjectInputStream(bais)) {
                Object o = ois.readObject();
            } catch (EOFException eof) {
                // normal completion
            } catch (ClassNotFoundException cnf) {
                Assert.fail("Deserializing", cnf);
            }
            Assert.assertTrue(allowed, "filter should have thrown an exception");
        } catch (IllegalArgumentException iae) {
            Assert.fail("bad format pattern", iae);
        } catch (InvalidClassException ice) {
            Assert.assertFalse(allowed, "filter should not have thrown an exception: " + ice);
        } catch (IOException ioe) {
            Assert.fail("Unexpected IOException", ioe);
        }
    }
 
Example #9
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: IIOPInputStream.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void skipCustomUsingFVD(ValueMember[] fields,
                                com.sun.org.omg.SendingContext.CodeBase sender)
                                throws InvalidClassException, StreamCorruptedException,
                                       ClassNotFoundException, IOException
{
    readFormatVersion();
    boolean calledDefaultWriteObject = readBoolean();

    if (calledDefaultWriteObject)
        throwAwayData(fields, sender);

    if (getStreamFormatVersion() == 2) {

        ((ValueInputStream)getOrbStream()).start_value();
        ((ValueInputStream)getOrbStream()).end_value();
    }
}
 
Example #10
Source Project: DataVec   Author: deeplearning4j   File: SparkTransformServerChooser.java    License: Apache License 2.0 6 votes vote down vote up
public void runMain(String[] args) throws Exception {

        int pos = getMatchingPosition(args, "-dt", "--dataType");
        if (pos == -1) {
            log.error("no valid options");
            log.error("-dt, --dataType   Options: [CSV, IMAGE]");
            throw new Exception("no valid options");
        } else {
            transformDataType = TransformDataType.valueOf(args[pos + 1]);
        }

        switch (transformDataType) {
            case CSV:
                sparkTransformServer = new CSVSparkTransformServer();
                break;
            case IMAGE:
                sparkTransformServer = new ImageSparkTransformServer();
                break;
            default:
                throw new InvalidClassException("no matching SparkTransform class");
        }

        sparkTransformServer.runMain(args);
    }
 
Example #11
Source Project: org.openntf.domino   Author: OpenNTF   File: Session.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
	//super.readExternal(in);
	parent = Factory.getWrapperFactory();
	int version = in.readInt();
	if (version != EXTERNALVERSIONUID) {
		throw new InvalidClassException("Cannot read dataversion " + version);
	}

	sessionType_ = (SessionType) in.readObject();
	username_ = (String) in.readObject();
	currentDatabaseApiPath_ = (String) in.readObject();

	isAutoMime_ = (AutoMime) in.readObject();
	fixes_ = (Set<Fixes>) in.readObject();
	eventFactory_ = (IDominoEventFactory) in.readObject();
	featureRestricted_ = in.readBoolean();

}
 
Example #12
Source Project: jdk8u60   Author: chenghanpeng   File: IIOPInputStream.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void skipCustomUsingFVD(ValueMember[] fields,
                                com.sun.org.omg.SendingContext.CodeBase sender)
                                throws InvalidClassException, StreamCorruptedException,
                                       ClassNotFoundException, IOException
{
    readFormatVersion();
    boolean calledDefaultWriteObject = readBoolean();

    if (calledDefaultWriteObject)
        throwAwayData(fields, sender);

    if (getStreamFormatVersion() == 2) {

        ((ValueInputStream)getOrbStream()).start_value();
        ((ValueInputStream)getOrbStream()).end_value();
    }
}
 
Example #13
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: Ser.java    License: MIT License 6 votes vote down vote up
private static void writeInternal(byte type, Object object, DataOutput out) throws IOException {
    out.writeByte(type);
    switch (type) {
        case ZRULES:
            ((ZoneRules) object).writeExternal(out);
            break;
        case ZOT:
            ((ZoneOffsetTransition) object).writeExternal(out);
            break;
        case ZOTRULE:
            ((ZoneOffsetTransitionRule) object).writeExternal(out);
            break;
        default:
            throw new InvalidClassException("Unknown serialized type");
    }
}
 
Example #14
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CheckArrayTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test SharedSecrets checkArray with unmodified ObjectInputStream.
 */
@Test(dataProvider = "Patterns")
public void normalOIS(String pattern, int arraySize, Object[] array) throws IOException {
    ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);
    byte[] bytes = SerialFilterTest.writeObjects(array);
    try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
         ObjectInputStream ois = new ObjectInputStream(bais)) {
        // Check the arraysize against the filter
        try {
            ObjectInputFilter.Config.setObjectInputFilter(ois, filter);
            SharedSecrets.getJavaOISAccess()
                    .checkArray(ois, array.getClass(), arraySize);
            Assert.assertTrue(array.length >= arraySize,
                    "Should have thrown InvalidClassException due to array size");
        } catch (InvalidClassException ice) {
            Assert.assertFalse(array.length > arraySize,
                    "Should NOT have thrown InvalidClassException due to array size");
        }
    }
}
 
Example #15
Source Project: jdk8u_jdk   Author: JetBrains   File: SerialFilterTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that returning null from a filter causes deserialization to fail.
 */
@Test(expectedExceptions=InvalidClassException.class)
static void testNullStatus() throws IOException {
    byte[] bytes = writeObjects(0); // an Integer
    try {
        Object o = validate(bytes, new ObjectInputFilter() {
            public ObjectInputFilter.Status checkInput(ObjectInputFilter.FilterInfo f) {
                return null;
            }
        });
    } catch (InvalidClassException ice) {
        System.out.printf("Success exception: %s%n", ice);
        throw ice;
    }
}
 
Example #16
Source Project: java-stellar-sdk   Author: stellar   File: XdrString.java    License: Apache License 2.0 5 votes vote down vote up
public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
    int size = stream.readInt();
    if (size > maxSize) {
        throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
    }
    byte[] bytes = new byte[size];
    stream.read(bytes);
    return new XdrString(bytes);
}
 
Example #17
Source Project: Java8CN   Author: Java8-CNAPI-Team   File: Ser.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeInternal(byte type, Object object, ObjectOutput out) throws IOException {
    out.writeByte(type);
    switch (type) {
        case CHRONO_TYPE:
            ((AbstractChronology) object).writeExternal(out);
            break;
        case CHRONO_LOCAL_DATE_TIME_TYPE:
            ((ChronoLocalDateTimeImpl<?>) object).writeExternal(out);
            break;
        case CHRONO_ZONE_DATE_TIME_TYPE:
            ((ChronoZonedDateTimeImpl<?>) object).writeExternal(out);
            break;
        case JAPANESE_DATE_TYPE:
            ((JapaneseDate) object).writeExternal(out);
            break;
        case JAPANESE_ERA_TYPE:
            ((JapaneseEra) object).writeExternal(out);
            break;
        case HIJRAH_DATE_TYPE:
            ((HijrahDate) object).writeExternal(out);
            break;
        case MINGUO_DATE_TYPE:
            ((MinguoDate) object).writeExternal(out);
            break;
        case THAIBUDDHIST_DATE_TYPE:
            ((ThaiBuddhistDate) object).writeExternal(out);
            break;
        case CHRONO_PERIOD_TYPE:
            ((ChronoPeriodImpl) object).writeExternal(out);
            break;
        default:
            throw new InvalidClassException("Unknown serialized type");
    }
}
 
Example #18
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: CheckInputOrderTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test:
 *   "global filter reject" + "specific ObjectInputStream filter is empty" => should reject
 *   "global filter reject" + "specific ObjectInputStream filter allow"    => should allow
 */
@Test(dataProvider="Patterns")
public void testRejectedInGlobal(Object toDeserialized, String pattern, boolean allowed) throws Exception {
    byte[] bytes = SerialFilterTest.writeObjects(toDeserialized);
    ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);

    try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bais)) {
        ObjectInputFilter.Config.setObjectInputFilter(ois, filter);
        Object o = ois.readObject();
        assertTrue(allowed, "filter should have thrown an exception");
    } catch (InvalidClassException ice) {
        assertFalse(allowed, "filter should have thrown an exception");
    }
}
 
Example #19
Source Project: terracotta-platform   Author: Terracotta-OSS   File: SerializationCodec.java    License: Apache License 2.0 5 votes vote down vote up
private static ObjectStreamClass checkForCompatibility(ObjectStreamClass descriptor, ObjectStreamClass substitution) throws InvalidClassException {
  if (descriptor.getSerialVersionUID() != substitution.getSerialVersionUID()) {
    throw new InvalidClassException(substitution.getName(),
        "substitute class incompatible: " +
            "stream classdesc serialVersionUID = " + descriptor.getSerialVersionUID() +
            ", substitute class serialVersionUID = " + substitution.getSerialVersionUID());
  } else {
    LOGGER.debug("Shading Auto-Substitution: {} -> {}", descriptor, substitution);
    return substitution;
  }
}
 
Example #20
Source Project: jeddict   Author: jeddict   File: PreferenceUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static Object deserialize(byte[] objectData, ClassLoader classLoader) throws InvalidClassException {
    if (objectData == null) {
        throw new IllegalArgumentException("The byte[] must not be null");
    }
    ByteArrayInputStream bais = new ByteArrayInputStream(objectData);
    return deserialize(bais, classLoader);
}
 
Example #21
Source Project: dragonwell8_jdk   Author: alibaba   File: Ser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void writeInternal(byte type, Object object, ObjectOutput out) throws IOException {
    out.writeByte(type);
    switch (type) {
        case CHRONO_TYPE:
            ((AbstractChronology) object).writeExternal(out);
            break;
        case CHRONO_LOCAL_DATE_TIME_TYPE:
            ((ChronoLocalDateTimeImpl<?>) object).writeExternal(out);
            break;
        case CHRONO_ZONE_DATE_TIME_TYPE:
            ((ChronoZonedDateTimeImpl<?>) object).writeExternal(out);
            break;
        case JAPANESE_DATE_TYPE:
            ((JapaneseDate) object).writeExternal(out);
            break;
        case JAPANESE_ERA_TYPE:
            ((JapaneseEra) object).writeExternal(out);
            break;
        case HIJRAH_DATE_TYPE:
            ((HijrahDate) object).writeExternal(out);
            break;
        case MINGUO_DATE_TYPE:
            ((MinguoDate) object).writeExternal(out);
            break;
        case THAIBUDDHIST_DATE_TYPE:
            ((ThaiBuddhistDate) object).writeExternal(out);
            break;
        case CHRONO_PERIOD_TYPE:
            ((ChronoPeriodImpl) object).writeExternal(out);
            break;
        default:
            throw new InvalidClassException("Unknown serialized type");
    }
}
 
Example #22
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: XPathException.java    License: MIT License 5 votes vote down vote up
/**
 * Reads the "cause" field from the stream.
 * And initializes the "cause" if it wasn't
 * done before.
 *
 * @param in stream used for deserialization
 * @throws IOException thrown by <code>ObjectInputStream</code>
 * @throws ClassNotFoundException  thrown by <code>ObjectInputStream</code>
 */
private void readObject(ObjectInputStream in)
        throws IOException, ClassNotFoundException
{
    ObjectInputStream.GetField fields = in.readFields();
    Throwable scause = (Throwable) fields.get("cause", null);

    if (super.getCause() == null && scause != null) {
        try {
            super.initCause(scause);
        } catch(IllegalStateException e) {
            throw new InvalidClassException("Inconsistent state: two causes");
        }
    }
}
 
Example #23
Source Project: dragonwell8_jdk   Author: alibaba   File: SerialFilterTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that returning null from a filter causes deserialization to fail.
 */
@Test(expectedExceptions=InvalidClassException.class)
static void testNullStatus() throws IOException {
    byte[] bytes = writeObjects(0); // an Integer
    try {
        Object o = validate(bytes, new ObjectInputFilter() {
            public ObjectInputFilter.Status checkInput(ObjectInputFilter.FilterInfo f) {
                return null;
            }
        });
    } catch (InvalidClassException ice) {
        System.out.printf("Success exception: %s%n", ice);
        throw ice;
    }
}
 
Example #24
Source Project: dragonwell8_jdk   Author: alibaba   File: SerialFilterTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a filter from a pattern and API factory, then serialize and
 * deserialize an object and check allowed or reject.
 *
 * @param pattern the pattern
 * @param object the test object
 * @param allowed the expected result from ObjectInputStream (exception or not)
 */
static void testPatterns(String pattern, Object object, boolean allowed) {
    try {
        byte[] bytes = SerialFilterTest.writeObjects(object);
        ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);
        validate(bytes, filter);
        Assert.assertTrue(allowed, "filter should have thrown an exception");
    } catch (IllegalArgumentException iae) {
        Assert.fail("bad format pattern", iae);
    } catch (InvalidClassException ice) {
        Assert.assertFalse(allowed, "filter should not have thrown an exception: " + ice);
    } catch (IOException ioe) {
        Assert.fail("Unexpected IOException", ioe);
    }
}
 
Example #25
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: CheckInputOrderTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test:
 *   "global filter reject" + "specific ObjectInputStream filter is empty" => should reject
 *   "global filter reject" + "specific ObjectInputStream filter allow"    => should allow
 */
@Test(dataProvider="Patterns")
public void testRejectedInGlobal(Object toDeserialized, String pattern, boolean allowed) throws Exception {
    byte[] bytes = SerialFilterTest.writeObjects(toDeserialized);
    ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern);

    try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bais)) {
        ObjectInputFilter.Config.setObjectInputFilter(ois, filter);
        Object o = ois.readObject();
        assertTrue(allowed, "filter should have thrown an exception");
    } catch (InvalidClassException ice) {
        assertFalse(allowed, "filter should have thrown an exception");
    }
}
 
Example #26
Source Project: j2objc   Author: google   File: SerializationTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testSerialVersionUidChange() throws Exception {
    // this was created by serializing a SerialVersionUidChanged with serialVersionUID = 0L
    String s = "aced0005737200396c6962636f72652e6a6176612e696f2e53657269616c697a6174696f6e54657"
            + "3742453657269616c56657273696f6e5569644368616e67656400000000000000000200014900016"
            + "1787000000003";
    try {
        SerializationTester.deserializeHex(s);
        fail();
    } catch (InvalidClassException expected) {
    }
}
 
Example #27
Source Project: TencentKona-8   Author: Tencent   File: IIOPInputStream.java    License: GNU General Public License v2.0 5 votes vote down vote up
void readFields(java.util.Map fieldToValueMap)
    throws InvalidClassException, StreamCorruptedException,
           ClassNotFoundException, IOException {

    if (mustUseRemoteValueMembers()) {
        inputRemoteMembersForReadFields(fieldToValueMap);
    } else
        inputCurrentClassFieldsForReadFields(fieldToValueMap);
}
 
Example #28
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Ser.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void writeInternal(byte type, Object object, ObjectOutput out) throws IOException {
    out.writeByte(type);
    switch (type) {
        case CHRONO_TYPE:
            ((AbstractChronology) object).writeExternal(out);
            break;
        case CHRONO_LOCAL_DATE_TIME_TYPE:
            ((ChronoLocalDateTimeImpl<?>) object).writeExternal(out);
            break;
        case CHRONO_ZONE_DATE_TIME_TYPE:
            ((ChronoZonedDateTimeImpl<?>) object).writeExternal(out);
            break;
        case JAPANESE_DATE_TYPE:
            ((JapaneseDate) object).writeExternal(out);
            break;
        case JAPANESE_ERA_TYPE:
            ((JapaneseEra) object).writeExternal(out);
            break;
        case HIJRAH_DATE_TYPE:
            ((HijrahDate) object).writeExternal(out);
            break;
        case MINGUO_DATE_TYPE:
            ((MinguoDate) object).writeExternal(out);
            break;
        case THAIBUDDHIST_DATE_TYPE:
            ((ThaiBuddhistDate) object).writeExternal(out);
            break;
        case CHRONO_PERIOD_TYPE:
            ((ChronoPeriodImpl) object).writeExternal(out);
            break;
        default:
            throw new InvalidClassException("Unknown serialized type");
    }
}
 
Example #29
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: SerialFilterTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that returning null from a filter causes deserialization to fail.
 */
@Test(expectedExceptions=InvalidClassException.class)
static void testNullStatus() throws IOException {
    byte[] bytes = writeObjects(0); // an Integer
    try {
        Object o = validate(bytes, new ObjectInputFilter() {
            public ObjectInputFilter.Status checkInput(ObjectInputFilter.FilterInfo f) {
                return null;
            }
        });
    } catch (InvalidClassException ice) {
        System.out.printf("Success exception: %s%n", ice);
        throw ice;
    }
}
 
Example #30
Source Project: Ngram-Graphs   Author: ayushoriginal   File: CachedDocumentComparator.java    License: Apache License 2.0 5 votes vote down vote up
public GraphSimilarity getSimilarityBetween(Object oFirst, Object oSecond) throws InvalidClassException {
    if (!((oFirst instanceof NGramDocument) && (oSecond instanceof NGramDocument)))
        throw new InvalidClassException("Both operands should be Documents (" + NGramDocument.class.getName() + 
                " class)");
    NGramDocument dFirst = (NGramDocument)oFirst;
    NGramDocument dSecond = (NGramDocument)oSecond;
    NGramCachedGraphComparator gcComparator = new NGramCachedGraphComparator();
    NGramHistogramComparator hcComparator = new NGramHistogramComparator();
    
    GraphSimilarity[] saSimil = new GraphSimilarity[2];
    //gcComparator.setNotificationListener(this); // Set this to listener
    // Graph GraphSimilarity
    saSimil[0] = gcComparator.getSimilarityBetween(dFirst.getDocumentGraph(), dSecond.getDocumentGraph());
    sGraph = saSimil[0];
    // Histogram GraphSimilarity
    saSimil[1] = hcComparator.getSimilarityBetween(dFirst.getDocumentHistogram(), dSecond.getDocumentHistogram());
    sHistogram = saSimil[1];
    
    GraphSimilarity sSimil = new GraphSimilarity();
    sSimil.ContainmentSimilarity = saSimil[0].ContainmentSimilarity * GraphImportance +
            saSimil[1].ContainmentSimilarity * (1 - GraphImportance);
    sSimil.ValueSimilarity = saSimil[0].ValueSimilarity * GraphImportance +
            saSimil[1].ValueSimilarity * (1 - GraphImportance);
    sSimil.SizeSimilarity = saSimil[0].SizeSimilarity * GraphImportance +
            saSimil[1].SizeSimilarity * (1 - GraphImportance);
            
    return sSimil;
}