Java 类java.io.InvalidClassException 实例源码

项目:GitHub    文件:WelcomeActivity.java   
/**
 * 初始化应用数据
 */
private String initAppData() {
    PreferenceHelper.loadDefaults();
    //TODO 测试,待删除
    if (PreferenceHelper.getSharedPreferences().getBoolean(WeatherSettings.SETTINGS_FIRST_USE.getId(), false)) {
        try {
            PreferenceHelper.savePreference(WeatherSettings.SETTINGS_CURRENT_CITY_ID, "101020100");
            PreferenceHelper.savePreference(WeatherSettings.SETTINGS_FIRST_USE, false);
        } catch (InvalidClassException e) {
            e.printStackTrace();
        }
    }
    Log.d(TAG, "importCityData start");
    CityDBUtil.importCityData();
    Log.d(TAG, "importCityData end");
    return null;
}
项目:GitHub    文件:CityManagerPresenter.java   
@Override
public void deleteCity(String cityId) {

    Observable.just(deleteCityFromDBAndReturnCurrentCityId(cityId))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(currentCityId -> {
                if (currentCityId == null)
                    return;
                try {
                    PreferenceHelper.savePreference(WeatherSettings.SETTINGS_CURRENT_CITY_ID, currentCityId);
                } catch (InvalidClassException e) {
                    e.printStackTrace();
                }
            });
}
项目:jLib    文件:JavaLayerUtils.java   
/**
 * Deserializes an object from the given <code>InputStream</code>.
 * The deserialization is delegated to an <code>
 * ObjectInputStream</code> instance. 
 * 
 * @param in    The <code>InputStream</code> to deserialize an object
 *              from.
 * 
 * @return The object deserialized from the stream. 
 * @exception IOException is thrown if there was a problem reading
 *      the underlying stream, or an object could not be deserialized
 *      from the stream.
 * 
 * @see java.io.ObjectInputStream
 */
static public Object deserialize(InputStream in)
    throws IOException
{
    if (in==null)
        throw new NullPointerException("in");

    ObjectInputStream objIn = new ObjectInputStream(in);

    Object obj;

    try
    {
        obj = objIn.readObject();
    }
    catch (ClassNotFoundException ex)
    {
        throw new InvalidClassException(ex.toString());
    }

    return obj;
}
项目:lams    文件:HttpInvokerClientInterceptor.java   
/**
 * Convert the given HTTP invoker access exception to an appropriate
 * Spring RemoteAccessException.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw
 */
protected RemoteAccessException convertHttpInvokerAccessException(Throwable ex) {
    if (ex instanceof ConnectException) {
        return new RemoteConnectFailureException(
                "Could not connect to HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
    }

    if (ex instanceof ClassNotFoundException || ex instanceof NoClassDefFoundError ||
            ex instanceof InvalidClassException) {
        return new RemoteAccessException(
                "Could not deserialize result from HTTP invoker remote service [" + getServiceUrl() + "]", ex);
    }

    return new RemoteAccessException(
                "Could not access HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
}
项目:java-logging    文件:ReformLoggingLayoutTest.java   
@Test
public void testDefaultOutputWithBadException() throws JoranException, IOException {
    configLogback(LOGBACK_WITH_THREAD);

    String message = "test output with bad exception";

    log.error(message, new InvalidClassException("Class null is invalid"));

    String logger = AbstractLoggingException.class.getCanonicalName();
    String errorClass = InvalidClassException.class.getCanonicalName();
    String message2 = String.format("Bad implementation of '%s' in use", errorClass);

    String output = baos.toString();

    // there must be original log
    assertThat(output).containsPattern(
        DEFAULT_DATE_FORMAT + ERROR + getThreadName() + getLogger() + message + "\n"
    );
    // alongside log about alert level misuse
    assertThat(output).containsPattern(
        DEFAULT_DATE_FORMAT + ERROR + getThreadName() + logger + ":\\d+: \\[P1\\] 0. " + message2 + "\n"
    );
}
项目:OpenJSharp    文件:IIOPInputStream.java   
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();
    }
}
项目:OpenJSharp    文件:Ser.java   
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");
    }
}
项目:playTorrent    文件:Torrent.java   
private static ArrayList<String> convertStringFromObject(Object value) throws InvalidClassException, UnsupportedEncodingException {
    if (value == null) {
        return null;
    }

    ArrayList<String> stringArrayList = new ArrayList<>();
    if (value instanceof ArrayList) {
        for (Object object : (ArrayList<?>)value) {
            ArrayList<String> recursiveList = convertStringFromObject(object);
            if (ValidationUtils.isEmptyList(recursiveList) == false) {
                stringArrayList.addAll(recursiveList);
            }
        }
    } else if (value instanceof ByteBuffer) {
        byte[] stringBytes = ((ByteBuffer)value).array();
        stringArrayList.add(new String(stringBytes, "UTF-8"));
    } else {
        throw new InvalidClassException("value is not array list or string [" + value.getClass() + "]");
    }

    return stringArrayList;
}
项目:OperatieBRP    文件:StreamUtils.java   
/**
 * Deserialize message.
 * @param data bytes
 * @return message
 * @throws IOException if an I/O error occurs when deserializing the message
 */
static Message deserializeMessage(final byte[] data) throws IOException {
    final ByteArrayInputStream byteInput = new ByteArrayInputStream(data);
    final ObjectInputStream objectInput = new ObjectInputStream(byteInput);

    try {
        return (Message) objectInput.readObject();
    } catch (final ClassCastException | ClassNotFoundException e) {
        final InvalidClassException ice = new InvalidClassException(
                "Could not deserialize object from received data");
        ice.initCause(e);
        throw ice;
    } finally {
        IOUtils.closeSilently(byteInput);
        IOUtils.closeSilently(objectInput);
    }
}
项目:jdk8u-jdk    文件:Ser.java   
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");
    }
}
项目:jdk8u-jdk    文件:GlobalFilterTest.java   
/**
     * 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);
        }
    }
项目:jdk8u-jdk    文件:FilterUSRTest.java   
@Test(dataProvider = "bindData")
public void UnicastServerRef(String name, Object obj, int expectedFilterCount) throws RemoteException {
    try {
        RemoteImpl impl = RemoteImpl.create();
        UnicastServerRef ref = new UnicastServerRef(new LiveRef(0), impl.checker);

        Echo client = (Echo) ref.exportObject(impl, null, false);

        int count = client.filterCount(obj);
        System.out.printf("count: %d, obj: %s%n", count, obj);
        Assert.assertEquals(count, expectedFilterCount, "wrong number of filter calls");
    } catch (RemoteException rex) {
        if (expectedFilterCount == -1 &&
                UnmarshalException.class.equals(rex.getCause().getClass()) &&
                InvalidClassException.class.equals(rex.getCause().getCause().getClass())) {
            return; // normal expected exception
        }
        rex.printStackTrace();
        Assert.fail("unexpected remote exception", rex);
    } catch (Exception ex) {
        Assert.fail("unexpected exception", ex);
    }
}
项目:openjdk-jdk10    文件:IIOPInputStream.java   
private boolean invokeObjectReader(ObjectStreamClass osc, Object obj, Class aclass)
    throws InvalidClassException, StreamCorruptedException,
           ClassNotFoundException, IOException
{
    try {
        return osc.invokeReadObject( obj, this ) ;
    } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t instanceof ClassNotFoundException)
            throw (ClassNotFoundException)t;
        else if (t instanceof IOException)
            throw (IOException)t;
        else if (t instanceof RuntimeException)
            throw (RuntimeException) t;
        else if (t instanceof Error)
            throw (Error) t;
        else
            // XXX I18N, logging needed.
            throw new Error("internal error");
    }
}
项目:openjdk-jdk10    文件:IIOPInputStream.java   
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();
    }
}
项目:openjdk-jdk10    文件:Ser.java   
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");
    }
}
项目:openjdk-jdk10    文件:TestSerialization.java   
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");
    }
}
项目:openjdk-jdk10    文件:PackageAccessTest.java   
public static void main(String[] args) throws Exception {
    setup();

    try (URLClassLoader ldr =
        new URLClassLoader(new URL[]{ new URL("file:foo.jar") },
                PackageAccessTest.class.getClassLoader())) {
        bcl = Class.forName("B", true, ldr);
        dcl = Class.forName("D", true, ldr);

        Object b = bcl.newInstance();
        try {
            swizzle(b);
            throw new Error("expected InvalidClassException for class B");
        } catch (InvalidClassException e) {
            System.out.println("caught " + e);
            e.printStackTrace();
        }
        if (A.packagePrivateConstructorInvoked) {
            throw new Error("package private constructor of A invoked");
        }

        Object d = dcl.newInstance();
        swizzle(d);
    }
}
项目:openjdk-jdk10    文件:GlobalFilterTest.java   
/**
     * 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);
        }
    }
项目:jlayer    文件:JavaLayerUtils.java   
/**
 * Deserializes an object from the given <code>InputStream</code>.
 * The deserialization is delegated to an <code>
 * ObjectInputStream</code> instance. 
 * 
 * @param in    The <code>InputStream</code> to deserialize an object
 *              from.
 * 
 * @return The object deserialized from the stream. 
 * @exception IOException is thrown if there was a problem reading
 *      the underlying stream, or an object could not be deserialized
 *      from the stream.
 * 
 * @see java.io.ObjectInputStream
 */
static public Object deserialize(InputStream in)
    throws IOException
{
    if (in==null)
        throw new NullPointerException("in");

    ObjectInputStream objIn = new ObjectInputStream(in);

    Object obj;

    try
    {
        obj = objIn.readObject();
    }
    catch (ClassNotFoundException ex)
    {
        throw new InvalidClassException(ex.toString());
    }

    return obj;
}
项目:openjdk9    文件:IIOPInputStream.java   
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();
    }
}
项目:openjdk9    文件:Ser.java   
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");
    }
}
项目:openjdk9    文件:TestSerialization.java   
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");
    }
}
项目:Ngram-Graphs    文件:SingleLinkClusterer.java   
public static void main(String[] args) {
    SingleLinkClusterer s = new SingleLinkClusterer();
    SimilarityComparatorListener c = new SimilarityComparatorListener() {
        public ISimilarity getSimilarityBetween(Object oFirst, Object oSecond) throws InvalidClassException {
            ISimilarity res = new SimpleSimilarity(
                    org.apache.commons.lang.StringUtils.getLevenshteinDistance(
                    (String)oFirst, (String)oSecond));
            return res;
        }
    };
    HashSet hElements = new HashSet();
    hElements.add("p1");
    hElements.add("p10");
    hElements.add("p11");
    hElements.add("p21");
    hElements.add("p311");
    hElements.add("p4111");
    hElements.add("p4112");
    hElements.add("p4115");
    s.calculateClusters(hElements,c);
    System.out.println(gr.demokritos.iit.jinsect.utils.graphToDot(s.getHierarchy(), true));
}
项目:Ngram-Graphs    文件:SingleLinkClusterer.java   
public static void main(String[] args) {
    SingleLinkClusterer s = new SingleLinkClusterer();
    SimilarityComparatorListener c = new SimilarityComparatorListener() {
        public ISimilarity getSimilarityBetween(Object oFirst, Object oSecond) throws InvalidClassException {
            ISimilarity res = new SimpleSimilarity(
                    org.apache.commons.lang.StringUtils.getLevenshteinDistance(
                    (String)oFirst, (String)oSecond));
            return res;
        }
    };
    HashSet hElements = new HashSet();
    hElements.add("p1");
    hElements.add("p10");
    hElements.add("p11");
    hElements.add("p21");
    hElements.add("p311");
    hElements.add("p4111");
    hElements.add("p4112");
    hElements.add("p4115");
    s.calculateClusters(hElements,c);
    System.out.println(gr.demokritos.iit.jinsect.utils.graphToDot(s.getHierarchy(), true));
}
项目:Java8CN    文件:Ser.java   
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");
    }
}
项目:spring4-understanding    文件:HttpInvokerClientInterceptor.java   
/**
 * Convert the given HTTP invoker access exception to an appropriate
 * Spring RemoteAccessException.
 * @param ex the exception to convert
 * @return the RemoteAccessException to throw
 */
protected RemoteAccessException convertHttpInvokerAccessException(Throwable ex) {
    if (ex instanceof ConnectException) {
        return new RemoteConnectFailureException(
                "Could not connect to HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
    }

    if (ex instanceof ClassNotFoundException || ex instanceof NoClassDefFoundError ||
            ex instanceof InvalidClassException) {
        return new RemoteAccessException(
                "Could not deserialize result from HTTP invoker remote service [" + getServiceUrl() + "]", ex);
    }

    return new RemoteAccessException(
                "Could not access HTTP invoker remote service at [" + getServiceUrl() + "]", ex);
}
项目:QD    文件:RMIServiceImplementation.java   
private synchronized Map<String, Method> fillProvidingImplMethodsSync() {
    Map<String, Method> providingImplMethods = this.providingImplMethods;
    if (providingImplMethods != null) // double check
        return providingImplMethods;
    providingImplMethods = new HashMap<>();
    for (Method method : serviceInterface.getMethods()) {
        RMIOperation<T> operation = RMIOperation.valueOf(serviceName, method);
        try {
            method = implementation.getClass().getMethod(method.getName(),
                operation.getParametersMarshaller().getClasses(serialContext != null ? serialContext.getClassLoader() : null));
            method.setAccessible(true);
        } catch (NoSuchMethodException | InvalidClassException e) {
            throw new IllegalArgumentException(e);
        }
        providingImplMethods.put(operation.getSignature(), method); // previously added implementations are erased
    }
    // done, publish result (volatile write)
    return this.providingImplMethods = providingImplMethods;
}
项目:service-authorization    文件:AuthUtils.java   
/**
 * Dirty hack to fix <a href="https://github.com/spring-projects/spring-security-oauth/issues/665">Spring Security Issue</a>
 * If there is serialUid mismatch, replaces Uuid and tries de-serialize object again
 * Introduces mismatchCallback function to handle successful recovery of Uuid mismatch
 *
 * @param data             Data to de-serialize
 * @param mismatchCallback Mismatch callback. Executed in case of successful recovery
 * @param <T>              Type of Object
 * @return De-serialized object
 */
@SuppressWarnings("unchecked")
public static <T> T deserializeSafely(byte[] data, @Nullable Consumer<T> mismatchCallback) {
    try {
        return SerializationUtils.deserialize(data);
    } catch (IllegalArgumentException e) {
        boolean serialUidMismatch = java.io.InvalidClassException.class.equals(e.getCause().getClass());
        if (!serialUidMismatch) {
            throw e;
        }

        try {
            ObjectInputStream is = new SerialUidReplacingInputStream(new ByteArrayInputStream(data));
            T t = (T) is.readObject();
            if (null != mismatchCallback) {
                mismatchCallback.accept(t);
            }
            return t;
        } catch (IOException | ClassNotFoundException e1) {
            throw new IllegalArgumentException("Unable to serialize object", e1);
        }
    }
}
项目:DataVec    文件:SparkTransformServerChooser.java   
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);
    }
项目:clouseau    文件:TomcatStandardSessionObjectReader.java   
/**
 * Adds a helpful error message including the ClassLoader and all of its resource URLs matching the name of the
 * invalid class.
 */
private IOException wrapInvalidClassException(ClassLoader targetAppClassLoader, InvalidClassException e) {
    String classResourceName = e.classname.replace('.', '/') + ".class";
    String classFileResourceUrlString;
    try {
        Enumeration<URL> classFileResources = targetAppClassLoader.getResources(classResourceName);
        classFileResourceUrlString = Collections.list(classFileResources).toString();
    } catch (IOException x) {
        classFileResourceUrlString = "[Indeterminate due to " + x.toString() + "]";
    }
    String msg = getClass().getName() +
            " is incorrectly configured or incompatible with the session data. If your Clouseau and" +
            " target app JVMs are sufficiently similar, you probably have a classpath ordering problem." +
            " Found class " + e.classname + " at URLs " + classFileResourceUrlString + " via ClassLoader=" +
            targetAppClassLoader;
    return new IOException(msg, e);
}
项目:jdk8u_jdk    文件:Ser.java   
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");
    }
}
项目:jdk8u_jdk    文件:GlobalFilterTest.java   
/**
     * 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);
        }
    }
项目:jdk8u_jdk    文件:FilterUSRTest.java   
@Test(dataProvider = "bindData")
public void UnicastServerRef(String name, Object obj, int expectedFilterCount) throws RemoteException {
    try {
        RemoteImpl impl = RemoteImpl.create();
        UnicastServerRef ref = new UnicastServerRef(new LiveRef(0), impl.checker);

        Echo client = (Echo) ref.exportObject(impl, null, false);

        int count = client.filterCount(obj);
        System.out.printf("count: %d, obj: %s%n", count, obj);
        Assert.assertEquals(count, expectedFilterCount, "wrong number of filter calls");
    } catch (RemoteException rex) {
        if (expectedFilterCount == -1 &&
                UnmarshalException.class.equals(rex.getCause().getClass()) &&
                InvalidClassException.class.equals(rex.getCause().getCause().getClass())) {
            return; // normal expected exception
        }
        rex.printStackTrace();
        Assert.fail("unexpected remote exception", rex);
    } catch (Exception ex) {
        Assert.fail("unexpected exception", ex);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:IIOPInputStream.java   
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();
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:Ser.java   
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");
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:GlobalFilterTest.java   
/**
     * 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);
        }
    }
项目:lookaside_java-1.8.0-openjdk    文件:FilterUSRTest.java   
@Test(dataProvider = "bindData")
public void UnicastServerRef(String name, Object obj, int expectedFilterCount) throws RemoteException {
    try {
        RemoteImpl impl = RemoteImpl.create();
        UnicastServerRef ref = new UnicastServerRef(new LiveRef(0), impl.checker);

        Echo client = (Echo) ref.exportObject(impl, null, false);

        int count = client.filterCount(obj);
        System.out.printf("count: %d, obj: %s%n", count, obj);
        Assert.assertEquals(count, expectedFilterCount, "wrong number of filter calls");
    } catch (RemoteException rex) {
        if (expectedFilterCount == -1 &&
                UnmarshalException.class.equals(rex.getCause().getClass()) &&
                InvalidClassException.class.equals(rex.getCause().getCause().getClass())) {
            return; // normal expected exception
        }
        rex.printStackTrace();
        Assert.fail("unexpected remote exception", rex);
    } catch (Exception ex) {
        Assert.fail("unexpected exception", ex);
    }
}
项目:test-analyzer    文件:AbstractFactoryReturnValueGenerator.java   
protected void checkFactoryValidity(Class<? extends AbstractReturnValueFactory> factoryClass)
        throws InvalidClassException {
    try {
        Field instanceField = factoryClass.getField(INSTANCE_FIELD_NAME);

        if (!(Modifier.isStatic(instanceField.getModifiers()) && Modifier.isPublic(instanceField.getModifiers()))) {
            throw new InvalidClassException("The field " + INSTANCE_FIELD_NAME + " is not public and static.");
        }

        if (!instanceField.getGenericType().equals(factoryClass)) {
            throw new InvalidClassException(
                    "The field " + INSTANCE_FIELD_NAME + " is not of the type " + factoryClass.getName() + ".");
        }
    } catch (NoSuchFieldException ex) {
        throw new InvalidClassException(factoryClass.getName() + " does not have a public static field of name "
                + INSTANCE_FIELD_NAME + " of the type of the factory.");
    }
}
项目:EORA    文件:JavaLayerUtils.java   
/**
 * Deserializes an object from the given <code>InputStream</code>.
 * The deserialization is delegated to an <code>
 * ObjectInputStream</code> instance. 
 * 
 * @param in    The <code>InputStream</code> to deserialize an object
 *              from.
 * 
 * @return The object deserialized from the stream. 
 * @exception IOException is thrown if there was a problem reading
 *      the underlying stream, or an object could not be deserialized
 *      from the stream.
 * 
 * @see java.io.ObjectInputStream
 */
static public Object deserialize(InputStream in)
    throws IOException
{
    if (in==null)
        throw new NullPointerException("in");

    ObjectInputStream objIn = new ObjectInputStream(in);

    Object obj;

    try
    {
        obj = objIn.readObject();
    }
    catch (ClassNotFoundException ex)
    {
        throw new InvalidClassException(ex.toString());
    }

    return obj;
}
项目:jdk8u_corba    文件:IIOPInputStream.java   
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();
    }
}