Java Code Examples for java.io.InvalidClassException

The following are top voted examples for showing how to use java.io.InvalidClassException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: WelcomeActivity.java   View source code 8 votes vote down vote up
/**
 * 初始化应用数据
 */
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;
}
 
Example 2
Project: GitHub   File: CityManagerPresenter.java   View source code 7 votes vote down vote up
@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();
                }
            });
}
 
Example 3
Project: jLib   File: JavaLayerUtils.java   View source code 7 votes vote down vote up
/**
 * 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;
}
 
Example 4
Project: lams   File: HttpInvokerClientInterceptor.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 5
Project: java-logging   File: ReformLoggingLayoutTest.java   View source code 6 votes vote down vote up
@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"
    );
}
 
Example 6
Project: OpenJSharp   File: IIOPInputStream.java   View source code 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 7
Project: OpenJSharp   File: Ser.java   View source code 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 8
Project: playTorrent   File: Torrent.java   View source code 6 votes vote down vote up
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;
}
 
Example 9
Project: OperatieBRP   File: StreamUtils.java   View source code 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 10
Project: jdk8u-jdk   File: Ser.java   View source code 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 11
Project: jdk8u-jdk   File: GlobalFilterTest.java   View source code 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 12
Project: jdk8u-jdk   File: FilterUSRTest.java   View source code 6 votes vote down vote up
@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);
    }
}
 
Example 13
Project: openjdk-jdk10   File: IIOPInputStream.java   View source code 6 votes vote down vote up
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");
    }
}
 
Example 14
Project: openjdk-jdk10   File: IIOPInputStream.java   View source code 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 15
Project: openjdk-jdk10   File: Ser.java   View source code 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 16
Project: openjdk-jdk10   File: TestSerialization.java   View source code 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 17
Project: openjdk-jdk10   File: PackageAccessTest.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 18
Project: openjdk-jdk10   File: GlobalFilterTest.java   View source code 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 19
Project: jlayer   File: JavaLayerUtils.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 20
Project: openjdk9   File: IIOPInputStream.java   View source code 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 21
Project: openjdk9   File: Ser.java   View source code 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 22
Project: openjdk9   File: TestSerialization.java   View source code 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 23
Project: Ngram-Graphs   File: SingleLinkClusterer.java   View source code 6 votes vote down vote up
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));
}
 
Example 24
Project: Ngram-Graphs   File: SingleLinkClusterer.java   View source code 6 votes vote down vote up
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));
}
 
Example 25
Project: Java8CN   File: Ser.java   View source code 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 26
Project: spring4-understanding   File: HttpInvokerClientInterceptor.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 27
Project: QD   File: RMIServiceImplementation.java   View source code 6 votes vote down vote up
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;
}
 
Example 28
Project: service-authorization   File: AuthUtils.java   View source code 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 29
Project: DataVec   File: SparkTransformServerChooser.java   View source code 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 30
Project: clouseau   File: TomcatStandardSessionObjectReader.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 31
Project: jdk8u_jdk   File: Ser.java   View source code 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 32
Project: jdk8u_jdk   File: GlobalFilterTest.java   View source code 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 33
Project: jdk8u_jdk   File: FilterUSRTest.java   View source code 6 votes vote down vote up
@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);
    }
}
 
Example 34
Project: lookaside_java-1.8.0-openjdk   File: IIOPInputStream.java   View source code 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 35
Project: lookaside_java-1.8.0-openjdk   File: Ser.java   View source code 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 36
Project: lookaside_java-1.8.0-openjdk   File: GlobalFilterTest.java   View source code 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 37
Project: lookaside_java-1.8.0-openjdk   File: FilterUSRTest.java   View source code 6 votes vote down vote up
@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);
    }
}
 
Example 38
Project: test-analyzer   File: AbstractFactoryReturnValueGenerator.java   View source code 6 votes vote down vote up
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.");
	}
}
 
Example 39
Project: EORA   File: JavaLayerUtils.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 40
Project: jdk8u_corba   File: IIOPInputStream.java   View source code 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();
    }
}