Search in sources :

Example 1 with BinaryInvalidTypeException

use of org.apache.ignite.binary.BinaryInvalidTypeException in project ignite by apache.

the class BinaryUtils method doReadClass.

/**
     * @param in Binary input stream.
     * @param ctx Binary context.
     * @param ldr Class loader.
     * @param typeId Type id.
     * @return Class object specified at the input stream.
     * @throws BinaryObjectException If failed.
     */
public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, int typeId) throws BinaryObjectException {
    Class cls;
    if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
        cls = ctx.descriptorForTypeId(true, typeId, ldr, true).describedClass();
    else {
        String clsName = doReadClassName(in);
        try {
            cls = U.forName(clsName, ldr);
        } catch (ClassNotFoundException e) {
            throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
        }
        // forces registering of class by type id, at least locally
        ctx.descriptorForClass(cls, true);
    }
    return cls;
}
Also used : BinaryInvalidTypeException(org.apache.ignite.binary.BinaryInvalidTypeException)

Example 2 with BinaryInvalidTypeException

use of org.apache.ignite.binary.BinaryInvalidTypeException in project ignite by apache.

the class BinaryContext method descriptorForTypeId.

/**
     * @param userType User type or not.
     * @param typeId Type ID.
     * @param ldr Class loader.
     * @return Class descriptor.
     */
public BinaryClassDescriptor descriptorForTypeId(boolean userType, int typeId, ClassLoader ldr, boolean deserialize) {
    assert typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID;
    //TODO: As a workaround for IGNITE-1358 we always check the predefined map before without checking 'userType'
    BinaryClassDescriptor desc = predefinedTypes.get(typeId);
    if (desc != null)
        return desc;
    if (ldr == null)
        ldr = sysLdr;
    Class cls;
    try {
        cls = marshCtx.getClass(typeId, ldr);
        desc = descByCls.get(cls);
    } catch (ClassNotFoundException e) {
        // Class might have been loaded by default class loader.
        if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true, typeId, sysLdr, deserialize)) != null)
            return desc;
        throw new BinaryInvalidTypeException(e);
    } catch (IgniteCheckedException e) {
        // Class might have been loaded by default class loader.
        if (userType && !ldr.equals(sysLdr) && (desc = descriptorForTypeId(true, typeId, sysLdr, deserialize)) != null)
            return desc;
        throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
    }
    if (desc == null) {
        desc = registerClassDescriptor(cls, deserialize);
        assert desc.typeId() == typeId : "Duplicate typeId [typeId=" + typeId + ", cls=" + cls + ", desc=" + desc + "]";
    }
    return desc;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryInvalidTypeException(org.apache.ignite.binary.BinaryInvalidTypeException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 3 with BinaryInvalidTypeException

use of org.apache.ignite.binary.BinaryInvalidTypeException in project ignite by apache.

the class GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest method doTestGet.

/**
     * @throws Exception Exception.
     */
private void doTestGet(boolean withKeepBinary) throws Exception {
    try {
        clientMode = false;
        startGrid(0);
        clientMode = true;
        startGrid(1);
        Class valCls = grid(1).configuration().getClassLoader().loadClass(TEST_VALUE);
        assertTrue(grid(1).configuration().isClientMode());
        assertFalse(grid(0).configuration().isClientMode());
        IgniteCache cache1 = grid(1).cache(DEFAULT_CACHE_NAME);
        IgniteCache cache0 = grid(0).cache(DEFAULT_CACHE_NAME);
        if (withKeepBinary) {
            cache1 = cache1.withKeepBinary();
            cache0 = cache0.withKeepBinary();
        }
        cache1.put("key", valCls.newInstance());
        if (withKeepBinary) {
            BinaryObject obj = (BinaryObject) (cache0.get("key"));
            try {
                obj.deserialize();
                fail("Exception did not happened.");
            } catch (BinaryInvalidTypeException ignored) {
            // No-op.
            }
        } else
            try {
                cache0.get("key");
                fail("Exception did not happened.");
            } catch (BinaryInvalidTypeException ignored) {
            // No-op.
            }
    } finally {
        stopAllGrids();
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryInvalidTypeException(org.apache.ignite.binary.BinaryInvalidTypeException) IgniteCache(org.apache.ignite.IgniteCache)

Example 4 with BinaryInvalidTypeException

use of org.apache.ignite.binary.BinaryInvalidTypeException in project ignite by apache.

the class BinaryReaderExImpl method deserialize0.

/**
     * @return Deserialized object.
     * @throws BinaryObjectException If failed.
     */
@Nullable
private Object deserialize0() throws BinaryObjectException {
    Object obj;
    byte flag = in.readByte();
    switch(flag) {
        case NULL:
            obj = null;
            break;
        case HANDLE:
            int handlePos = start - in.readInt();
            obj = getHandle(handlePos);
            if (obj == null) {
                int retPos = in.position();
                streamPosition(handlePos);
                obj = BinaryUtils.doReadObject(in, ctx, ldr, this);
                streamPosition(retPos);
            }
            break;
        case OBJ:
            if (desc == null)
                desc = ctx.descriptorForTypeId(userType, typeId, ldr, true);
            streamPosition(dataStart);
            if (desc == null)
                throw new BinaryInvalidTypeException("Unknown type ID: " + typeId);
            obj = desc.read(this);
            streamPosition(footerStart + footerLen);
            break;
        case BYTE:
            obj = in.readByte();
            break;
        case SHORT:
            obj = in.readShort();
            break;
        case INT:
            obj = in.readInt();
            break;
        case LONG:
            obj = in.readLong();
            break;
        case FLOAT:
            obj = in.readFloat();
            break;
        case DOUBLE:
            obj = in.readDouble();
            break;
        case CHAR:
            obj = in.readChar();
            break;
        case BOOLEAN:
            obj = in.readBoolean();
            break;
        case DECIMAL:
            obj = BinaryUtils.doReadDecimal(in);
            break;
        case STRING:
            obj = BinaryUtils.doReadString(in);
            break;
        case UUID:
            obj = BinaryUtils.doReadUuid(in);
            break;
        case DATE:
            obj = BinaryUtils.doReadDate(in);
            break;
        case TIMESTAMP:
            obj = BinaryUtils.doReadTimestamp(in);
            break;
        case TIME:
            obj = BinaryUtils.doReadTime(in);
            break;
        case BYTE_ARR:
            obj = BinaryUtils.doReadByteArray(in);
            break;
        case SHORT_ARR:
            obj = BinaryUtils.doReadShortArray(in);
            break;
        case INT_ARR:
            obj = BinaryUtils.doReadIntArray(in);
            break;
        case LONG_ARR:
            obj = BinaryUtils.doReadLongArray(in);
            break;
        case FLOAT_ARR:
            obj = BinaryUtils.doReadFloatArray(in);
            break;
        case DOUBLE_ARR:
            obj = BinaryUtils.doReadDoubleArray(in);
            break;
        case CHAR_ARR:
            obj = BinaryUtils.doReadCharArray(in);
            break;
        case BOOLEAN_ARR:
            obj = BinaryUtils.doReadBooleanArray(in);
            break;
        case DECIMAL_ARR:
            obj = BinaryUtils.doReadDecimalArray(in);
            break;
        case STRING_ARR:
            obj = BinaryUtils.doReadStringArray(in);
            break;
        case UUID_ARR:
            obj = BinaryUtils.doReadUuidArray(in);
            break;
        case DATE_ARR:
            obj = BinaryUtils.doReadDateArray(in);
            break;
        case TIMESTAMP_ARR:
            obj = BinaryUtils.doReadTimestampArray(in);
            break;
        case TIME_ARR:
            obj = BinaryUtils.doReadTimeArray(in);
            break;
        case OBJ_ARR:
            obj = BinaryUtils.doReadObjectArray(in, ctx, ldr, this, true);
            break;
        case COL:
            obj = BinaryUtils.doReadCollection(in, ctx, ldr, this, true, null);
            break;
        case MAP:
            obj = BinaryUtils.doReadMap(in, ctx, ldr, this, true, null);
            break;
        case BINARY_OBJ:
            obj = BinaryUtils.doReadBinaryObject(in, ctx, false);
            ((BinaryObjectImpl) obj).context(ctx);
            if (!GridBinaryMarshaller.KEEP_BINARIES.get())
                obj = ((BinaryObject) obj).deserialize();
            break;
        case ENUM:
            obj = BinaryUtils.doReadEnum(in, BinaryUtils.doReadClass(in, ctx, ldr));
            break;
        case ENUM_ARR:
            obj = BinaryUtils.doReadEnumArray(in, ctx, ldr, BinaryUtils.doReadClass(in, ctx, ldr));
            break;
        case BINARY_ENUM:
            obj = BinaryUtils.doReadBinaryEnum(in, ctx);
            if (!GridBinaryMarshaller.KEEP_BINARIES.get())
                obj = ((BinaryObject) obj).deserialize();
            break;
        case CLASS:
            obj = BinaryUtils.doReadClass(in, ctx, ldr);
            break;
        case PROXY:
            obj = BinaryUtils.doReadProxy(in, ctx, ldr, this);
            break;
        case OPTM_MARSH:
            obj = BinaryUtils.doReadOptimized(in, ctx, ldr);
            break;
        default:
            throw new BinaryObjectException("Invalid flag value: " + flag);
    }
    return obj;
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryInvalidTypeException(org.apache.ignite.binary.BinaryInvalidTypeException) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

BinaryInvalidTypeException (org.apache.ignite.binary.BinaryInvalidTypeException)4 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)2 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 Nullable (org.jetbrains.annotations.Nullable)1