private void check() { if (done) { throw new HazelcastSerializationException("ClassDefinition is already built for " + classId); } }
@Override public Throwable createException(String message, Throwable cause) { return new HazelcastSerializationException(message, cause); } });
private Portable createNewPortableInstance(int factoryId, int classId) { final PortableFactory portableFactory = factories.get(factoryId); if (portableFactory == null) { throw new HazelcastSerializationException("Could not find PortableFactory for factory-id: " + factoryId); } final Portable portable = portableFactory.create(classId); if (portable == null) { throw new HazelcastSerializationException("Could not create Portable for class-id: " + classId); } return portable; }
private Portable createNewPortableInstance(int factoryId, int classId) { final PortableFactory portableFactory = factories.get(factoryId); if (portableFactory == null) { throw new HazelcastSerializationException("Could not find PortableFactory for factory-id: " + factoryId); } final Portable portable = portableFactory.create(classId); if (portable == null) { throw new HazelcastSerializationException("Could not create Portable for class-id: " + classId); } return portable; }
public static InputStream convertToInputStream(DataInput in, int offset) { if (!(in instanceof ByteArrayObjectDataInput)) { throw new HazelcastSerializationException("Cannot convert " + in.getClass().getName() + " to input stream"); } ByteArrayObjectDataInput byteArrayInput = (ByteArrayObjectDataInput) in; return new ByteArrayInputStream(byteArrayInput.data, offset, byteArrayInput.size - offset); }
static RuntimeException handleSerializeException(Object rootObject, Throwable e) { if (e instanceof OutOfMemoryError) { OutOfMemoryErrorDispatcher.onOutOfMemory((OutOfMemoryError) e); throw (Error) e; } if (e instanceof Error) { throw (Error) e; } String clazz = rootObject == null ? "null" : rootObject.getClass().getName(); throw new HazelcastSerializationException("Failed to serialize '" + clazz + '\'', e); }
private void skipBytesSafely(ObjectDataInput input, int count) throws IOException { if (input.skipBytes(count) != count) { throw new HazelcastSerializationException("Malformed serialization format"); } }
@Override // explicit cast to InputStream and intentionally omitting to close ObjectInputStream @SuppressFBWarnings({ "BC_UNCONFIRMED_CAST", "OS_OPEN_STREAM"}) public CustomClassLoadedObject read(ObjectDataInput in) throws IOException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); ObjectInputStream objectInputStream = newObjectInputStream(cl, null, (InputStream) in); try { return new CustomClassLoadedObject((Serializable) objectInputStream.readObject()); } catch (ClassNotFoundException e) { throw new HazelcastSerializationException(e); } }
private PortablePosition findPositionForReading(String path) throws IOException { if (raw) { throw new HazelcastSerializationException("Cannot read Portable fields after getRawDataInput() is called!"); } try { return PortablePositionNavigator.findPositionForReading(ctx, path, pathCursor); } finally { // The context is reset each time to enable its reuse in consecutive calls and avoid allocation ctx.reset(); } }
@Override public void readData(@Nonnull ObjectDataInput in) throws IOException { localParallelism = in.readInt(); name = in.readUTF(); try { metaSupplier = CustomClassLoadedObject.read(in); } catch (HazelcastSerializationException e) { throw new HazelcastSerializationException("Error deserializing vertex '" + name + "': " + e, e); } }
public void registerClassDefinitions(Collection<ClassDefinition> classDefinitions, boolean checkClassDefErrors) { final Map<Integer, ClassDefinition> classDefMap = createHashMap(classDefinitions.size()); for (ClassDefinition cd : classDefinitions) { if (classDefMap.containsKey(cd.getClassId())) { throw new HazelcastSerializationException("Duplicate registration found for class-id[" + cd.getClassId() + "]!"); } classDefMap.put(cd.getClassId(), cd); } for (ClassDefinition classDefinition : classDefinitions) { registerClassDefinition(classDefinition, classDefMap, checkClassDefErrors); } }
public void registerClassDefinitions(Collection<ClassDefinition> classDefinitions, boolean checkClassDefErrors) { final Map<Integer, ClassDefinition> classDefMap = createHashMap(classDefinitions.size()); for (ClassDefinition cd : classDefinitions) { if (classDefMap.containsKey(cd.getClassId())) { throw new HazelcastSerializationException("Duplicate registration found for class-id[" + cd.getClassId() + "]!"); } classDefMap.put(cd.getClassId(), cd); } for (ClassDefinition classDefinition : classDefinitions) { registerClassDefinition(classDefinition, classDefMap, checkClassDefErrors); } }
private Serializer createSerializerInstance(SerializerConfig serializerConfig, Class serializationType) { try { String className = serializerConfig.getClassName(); if (useDefaultConstructorOnly) { return ClassLoaderUtil.newInstance(classLoader, className); } else { return createSerializerInstanceWithFallback(serializationType, className); } } catch (Exception e) { throw new HazelcastSerializationException(e); } }
@Override public void readData(ObjectDataInput in) throws IOException { String klassName = in.readUTF(); try { klass = ClassLoaderUtil.loadClass(in.getClassLoader(), klassName); } catch (ClassNotFoundException e) { throw new HazelcastSerializationException("Failed to load class: " + klass, e); } }
private Serializer createSerializerInstance(SerializerConfig serializerConfig, Class serializationType) { try { String className = serializerConfig.getClassName(); if (useDefaultConstructorOnly) { return ClassLoaderUtil.newInstance(classLoader, className); } else { return createSerializerInstanceWithFallback(serializationType, className); } } catch (Exception e) { throw new HazelcastSerializationException(e); } }
@Override public void writeNullPortable(String fieldName, int factoryId, int classId) throws IOException { final ClassDefinition nestedClassDef = context.lookupClassDefinition(factoryId, classId, context.getVersion()); if (nestedClassDef == null) { throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!"); } builder.addPortableField(fieldName, nestedClassDef); }
private void checkPortableAttributes(FieldDefinition fd, Portable portable) { if (fd.getFactoryId() != portable.getFactoryId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + " Expected factory-id: " + fd.getFactoryId() + ", Actual factory-id: " + portable.getFactoryId()); } if (fd.getClassId() != portable.getClassId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + "Expected class-id: " + fd.getClassId() + ", Actual class-id: " + portable.getClassId()); } }
/** * @param ctx portable navigation context * @param fullPath full path - just for output * @return initialised HazelcastSerializationException with an unknown field at the current path token */ static HazelcastSerializationException createUnknownFieldException(PortableNavigatorContext ctx, String fullPath) { return new HazelcastSerializationException("Unknown field name: '" + fullPath + "' for ClassDefinition {id: " + ctx.getCurrentClassDefinition().getClassId() + ", version: " + ctx.getCurrentClassDefinition().getVersion() + "}"); }
@Override public void writePortable(String fieldName, Portable portable) throws IOException { if (portable == null) { throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!"); } int version = SerializationUtil.getPortableVersion(portable, context.getVersion()); ClassDefinition nestedClassDef = createNestedClassDef(portable, new ClassDefinitionBuilder(portable.getFactoryId(), portable.getClassId(), version)); builder.addPortableField(fieldName, nestedClassDef); }
@Override public void writePortable(String fieldName, Portable portable) throws IOException { if (portable == null) { throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!"); } int version = SerializationUtil.getPortableVersion(portable, context.getVersion()); ClassDefinition nestedClassDef = createNestedClassDef(portable, new ClassDefinitionBuilder(portable.getFactoryId(), portable.getClassId(), version)); builder.addPortableField(fieldName, nestedClassDef); }