/** * Throw exception on class duplication. * * @param clsName Class name. * @param id Type id. */ private static BinaryObjectException duplicateTypeIdException(String clsName, int id) { return new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']'); }
/** * Test verbose logging of object marshalling. * * @throws Exception If failed. */ @Test public void testFailedMarshallingLogging() throws Exception { BinaryMarshaller marshaller = createStandaloneBinaryMarshaller(); try { marshaller.marshal(new Value1()); } catch (BinaryObjectException ex) { assertTrue(ex.getMessage().contains( "object [typeName=org.apache.ignite.internal.binary.BinaryObjectExceptionSelfTest$Value1")); assertTrue(ex.getCause().getMessage().contains("field [name=objVal")); } }
/** * */ @Test public void testWrongMetadataNullField2() { BinaryObjectBuilder builder = binaries().builder("SomeType1"); builder.setField("dateField", null); builder.setField("objectField", null, Integer.class); BinaryObject obj = builder.build(); try { builder = binaries().builder(obj); builder.setField("dateField", new Date()); builder.build(); } catch (BinaryObjectException ex) { assertTrue(ex.getMessage().startsWith("Wrong value has been set")); } builder = binaries().builder(obj); try { builder.setField("objectField", new GridBinaryTestClasses.Company()); builder.build(); fail("BinaryObjectBuilder accepted wrong metadata"); } catch (BinaryObjectException ex) { assertTrue(ex.getMessage().startsWith("Wrong value has been set")); } }
/** * */ @Test public void testWrongMetadataNullField() { BinaryObjectBuilder builder = binaries().builder("SomeType"); builder.setField("dateField", null); builder.setField("objectField", null, Integer.class); builder.build(); try { builder = binaries().builder("SomeType"); builder.setField("dateField", new Date()); builder.build(); } catch (BinaryObjectException ex) { assertTrue(ex.getMessage().startsWith("Wrong value has been set")); } builder = binaries().builder("SomeType"); try { builder.setField("objectField", new GridBinaryTestClasses.Company()); builder.build(); fail("BinaryObjectBuilder accepted wrong metadata"); } catch (BinaryObjectException ex) { assertTrue(ex.getMessage().startsWith("Wrong value has been set")); } }
/** {@inheritDoc} */ private BinaryObjectException unsupported() { return new BinaryObjectException("Binary marshaller is not configured."); } }
/** * @throws Exception If failed. */ @Test public void testDuplicateNameSimpleNameMapper() throws Exception { BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true), null, null, null); Test1.Job job1 = new Test1().new Job(); Test2.Job job2 = new Test2().new Job(); marsh.marshal(job1); try { marsh.marshal(job2); } catch (BinaryObjectException e) { assertEquals(true, e.getMessage().contains("Failed to register class")); return; } assert false; }
/** * Check protocol version. * * @param protoVer Protocol version. */ public static void checkProtocolVersion(byte protoVer) { if (GridBinaryMarshaller.PROTO_VER != protoVer) throw new BinaryObjectException("Unsupported protocol version: " + protoVer); }
/** {@inheritDoc} */ @Override public String enumName() throws BinaryObjectException { throw new BinaryObjectException("Object is not enum."); }
/** {@inheritDoc} */ @Override public int enumOrdinal() throws BinaryObjectException { throw new BinaryObjectException("Object is not enum."); }
/** * Wraps an exception by adding the fieldName * * @param fieldName the name of the field, causes failure * @param e the cause of the deserialization failure * @return wrapping exception */ private BinaryObjectException wrapFieldException(String fieldName, Exception e) { if (S.INCLUDE_SENSITIVE) return new BinaryObjectException("Failed to read field: " + fieldName, e); else return new BinaryObjectException("Failed to read field.", e); }
/** * @param cnt Remaining bytes. */ private void ensureHasData(int cnt) { if (buf.remaining() < cnt) throw new BinaryObjectException("Not enough data to read the value " + "[requiredBytes=" + cnt + ", remainingBytes=" + buf.remaining() + ']'); } }
/** * Override binary class descriptor. * * @param other Other descriptor. * @throws BinaryObjectException If failed. */ private void override(TypeDescriptor other) throws BinaryObjectException { assert clsName.equals(other.clsName); if (canOverride) { mapper = other.mapper; serializer = other.serializer; identity = other.identity; affKeyFieldName = other.affKeyFieldName; isEnum = other.isEnum; enumMap = other.enumMap; canOverride = other.canOverride; } else if (!other.canOverride) throw new BinaryObjectException("Duplicate explicit class definition in configuration: " + clsName); } }
/** {@inheritDoc} */ @Nullable @Override public Object replace(Object target) { try { return mthd.invoke(target); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof BinaryObjectException) throw (BinaryObjectException)e.getTargetException(); throw new BinaryObjectException("Failed to execute writeReplace() method on " + target, e); } } }
/** {@inheritDoc} */ @Override public BinaryRawReader rawReader() { if (!raw) { streamPositionRandom(rawOff); raw = true; return this; } else throw new BinaryObjectException("Method \"rawReader\" can be called only once."); }
/** {@inheritDoc} */ @Override public int hashCode(BinaryObject obj) { if (obj == null) throw new BinaryObjectException("Cannot calculate hash code because binary object is null."); return hashCode0(obj); }
/** {@inheritDoc} */ @Override protected void marshal0(@Nullable Object obj, OutputStream out) throws IgniteCheckedException { byte[] arr = marshal(obj); try { out.write(arr); } catch (Exception e) { throw new BinaryObjectException("Failed to marshal the object: " + obj, e); } }
/** {@inheritDoc} */ @Override public void position(int pos) { if (remaining() + this.pos < pos) throw new BinaryObjectException("Position is out of bounds: " + pos); else this.pos = pos; }
/** * @return Instance. * @throws BinaryObjectException In case of error. */ private Object newInstance() throws BinaryObjectException { try { return ctor != null ? ctor.newInstance() : GridUnsafe.allocateInstance(cls); } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) { throw new BinaryObjectException("Failed to instantiate instance: " + cls, e); } }
throw new BinaryObjectException("Malformed input: partial character at end"); throw new BinaryObjectException("Malformed input around byte: " + off); throw new BinaryObjectException("Malformed input: partial character at end"); throw new BinaryObjectException("Malformed input around byte: " + (off - 1)); default: throw new BinaryObjectException("Malformed input around byte: " + off);
/** {@inheritDoc} */ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException { throw new BinaryObjectException("Test marshalling exception"); }