You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2018/03/19 06:27:04 UTC
[27/50] [abbrv] ignite git commit: IGNITE-6860 Add logging and
additional info while OptimizedMarshaller fails to serialize or deserialize
object.
IGNITE-6860 Add logging and additional info while OptimizedMarshaller fails to serialize or deserialize object.
Signed-off-by: Andrey Gura <ag...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c533e2cc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c533e2cc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c533e2cc
Branch: refs/heads/ignite-zk
Commit: c533e2ccb8dcbb2a9596befd4c4eda65a2f2fa0d
Parents: 7366809
Author: Ivan Daschinskiy <iv...@gmail.com>
Authored: Wed Mar 14 12:55:00 2018 +0300
Committer: Andrey Gura <ag...@apache.org>
Committed: Wed Mar 14 12:55:31 2018 +0300
----------------------------------------------------------------------
.../internal/binary/BinaryClassDescriptor.java | 382 ++++++++++---------
.../internal/binary/BinaryFieldAccessor.java | 61 ++-
.../optimized/OptimizedObjectInputStream.java | 103 ++---
.../optimized/OptimizedObjectOutputStream.java | 94 +++--
.../binary/BinaryObjectExceptionSelfTest.java | 41 ++
.../OptimizedObjectStreamSelfTest.java | 94 ++++-
6 files changed, 478 insertions(+), 297 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/c533e2cc/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
index 3e75982..bac5d40 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -530,283 +530,297 @@ public class BinaryClassDescriptor {
* @throws BinaryObjectException In case of error.
*/
void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
- assert obj != null;
- assert writer != null;
- assert mode != BinaryWriteMode.OPTIMIZED : "OptimizedMarshaller should not be used here: " + cls.getName();
+ try {
+ assert obj != null;
+ assert writer != null;
+ assert mode != BinaryWriteMode.OPTIMIZED : "OptimizedMarshaller should not be used here: " + cls.getName();
- writer.typeId(typeId);
+ writer.typeId(typeId);
- switch (mode) {
- case P_BYTE:
- case BYTE:
- writer.writeByteFieldPrimitive((byte) obj);
+ switch (mode) {
+ case P_BYTE:
+ case BYTE:
+ writer.writeByteFieldPrimitive((byte)obj);
- break;
+ break;
- case P_SHORT:
- case SHORT:
- writer.writeShortFieldPrimitive((short)obj);
+ case P_SHORT:
+ case SHORT:
+ writer.writeShortFieldPrimitive((short)obj);
- break;
+ break;
- case P_INT:
- case INT:
- writer.writeIntFieldPrimitive((int) obj);
+ case P_INT:
+ case INT:
+ writer.writeIntFieldPrimitive((int)obj);
- break;
+ break;
- case P_LONG:
- case LONG:
- writer.writeLongFieldPrimitive((long) obj);
+ case P_LONG:
+ case LONG:
+ writer.writeLongFieldPrimitive((long)obj);
- break;
+ break;
- case P_FLOAT:
- case FLOAT:
- writer.writeFloatFieldPrimitive((float) obj);
+ case P_FLOAT:
+ case FLOAT:
+ writer.writeFloatFieldPrimitive((float)obj);
- break;
+ break;
- case P_DOUBLE:
- case DOUBLE:
- writer.writeDoubleFieldPrimitive((double) obj);
+ case P_DOUBLE:
+ case DOUBLE:
+ writer.writeDoubleFieldPrimitive((double)obj);
- break;
+ break;
- case P_CHAR:
- case CHAR:
- writer.writeCharFieldPrimitive((char) obj);
+ case P_CHAR:
+ case CHAR:
+ writer.writeCharFieldPrimitive((char)obj);
- break;
+ break;
- case P_BOOLEAN:
- case BOOLEAN:
- writer.writeBooleanFieldPrimitive((boolean) obj);
+ case P_BOOLEAN:
+ case BOOLEAN:
+ writer.writeBooleanFieldPrimitive((boolean)obj);
- break;
+ break;
- case DECIMAL:
- writer.doWriteDecimal((BigDecimal)obj);
+ case DECIMAL:
+ writer.doWriteDecimal((BigDecimal)obj);
- break;
+ break;
- case STRING:
- writer.doWriteString((String)obj);
+ case STRING:
+ writer.doWriteString((String)obj);
- break;
+ break;
- case UUID:
- writer.doWriteUuid((UUID)obj);
+ case UUID:
+ writer.doWriteUuid((UUID)obj);
- break;
+ break;
- case DATE:
- writer.doWriteDate((Date)obj);
+ case DATE:
+ writer.doWriteDate((Date)obj);
- break;
+ break;
- case TIMESTAMP:
- writer.doWriteTimestamp((Timestamp)obj);
+ case TIMESTAMP:
+ writer.doWriteTimestamp((Timestamp)obj);
- break;
+ break;
- case TIME:
- writer.doWriteTime((Time)obj);
+ case TIME:
+ writer.doWriteTime((Time)obj);
- break;
+ break;
- case BYTE_ARR:
- writer.doWriteByteArray((byte[])obj);
+ case BYTE_ARR:
+ writer.doWriteByteArray((byte[])obj);
- break;
+ break;
- case SHORT_ARR:
- writer.doWriteShortArray((short[]) obj);
+ case SHORT_ARR:
+ writer.doWriteShortArray((short[])obj);
- break;
+ break;
- case INT_ARR:
- writer.doWriteIntArray((int[]) obj);
+ case INT_ARR:
+ writer.doWriteIntArray((int[])obj);
- break;
+ break;
- case LONG_ARR:
- writer.doWriteLongArray((long[]) obj);
+ case LONG_ARR:
+ writer.doWriteLongArray((long[])obj);
- break;
+ break;
- case FLOAT_ARR:
- writer.doWriteFloatArray((float[]) obj);
+ case FLOAT_ARR:
+ writer.doWriteFloatArray((float[])obj);
- break;
+ break;
- case DOUBLE_ARR:
- writer.doWriteDoubleArray((double[]) obj);
+ case DOUBLE_ARR:
+ writer.doWriteDoubleArray((double[])obj);
- break;
+ break;
- case CHAR_ARR:
- writer.doWriteCharArray((char[]) obj);
+ case CHAR_ARR:
+ writer.doWriteCharArray((char[])obj);
- break;
+ break;
- case BOOLEAN_ARR:
- writer.doWriteBooleanArray((boolean[]) obj);
+ case BOOLEAN_ARR:
+ writer.doWriteBooleanArray((boolean[])obj);
- break;
+ break;
- case DECIMAL_ARR:
- writer.doWriteDecimalArray((BigDecimal[]) obj);
+ case DECIMAL_ARR:
+ writer.doWriteDecimalArray((BigDecimal[])obj);
- break;
+ break;
- case STRING_ARR:
- writer.doWriteStringArray((String[]) obj);
+ case STRING_ARR:
+ writer.doWriteStringArray((String[])obj);
- break;
+ break;
- case UUID_ARR:
- writer.doWriteUuidArray((UUID[]) obj);
+ case UUID_ARR:
+ writer.doWriteUuidArray((UUID[])obj);
- break;
+ break;
- case DATE_ARR:
- writer.doWriteDateArray((Date[]) obj);
+ case DATE_ARR:
+ writer.doWriteDateArray((Date[])obj);
- break;
+ break;
- case TIMESTAMP_ARR:
- writer.doWriteTimestampArray((Timestamp[]) obj);
+ case TIMESTAMP_ARR:
+ writer.doWriteTimestampArray((Timestamp[])obj);
- break;
+ break;
- case TIME_ARR:
- writer.doWriteTimeArray((Time[]) obj);
+ case TIME_ARR:
+ writer.doWriteTimeArray((Time[])obj);
- break;
+ break;
- case OBJECT_ARR:
- writer.doWriteObjectArray((Object[])obj);
+ case OBJECT_ARR:
+ writer.doWriteObjectArray((Object[])obj);
- break;
+ break;
- case COL:
- writer.doWriteCollection((Collection<?>)obj);
+ case COL:
+ writer.doWriteCollection((Collection<?>)obj);
- break;
+ break;
- case MAP:
- writer.doWriteMap((Map<?, ?>)obj);
+ case MAP:
+ writer.doWriteMap((Map<?, ?>)obj);
- break;
+ break;
- case ENUM:
- writer.doWriteEnum((Enum<?>)obj);
+ case ENUM:
+ writer.doWriteEnum((Enum<?>)obj);
- break;
+ break;
- case BINARY_ENUM:
- writer.doWriteBinaryEnum((BinaryEnumObjectImpl)obj);
+ case BINARY_ENUM:
+ writer.doWriteBinaryEnum((BinaryEnumObjectImpl)obj);
- break;
+ break;
- case ENUM_ARR:
- writer.doWriteEnumArray((Object[])obj);
+ case ENUM_ARR:
+ writer.doWriteEnumArray((Object[])obj);
- break;
+ break;
- case CLASS:
- writer.doWriteClass((Class)obj);
+ case CLASS:
+ writer.doWriteClass((Class)obj);
- break;
+ break;
- case PROXY:
- writer.doWriteProxy((Proxy)obj, intfs);
+ case PROXY:
+ writer.doWriteProxy((Proxy)obj, intfs);
- break;
+ break;
- case BINARY_OBJ:
- writer.doWriteBinaryObject((BinaryObjectImpl)obj);
+ case BINARY_OBJ:
+ writer.doWriteBinaryObject((BinaryObjectImpl)obj);
- break;
+ break;
- case BINARY:
- if (preWrite(writer, obj)) {
- try {
- if (serializer != null)
- serializer.writeBinary(obj, writer);
- else
- ((Binarylizable)obj).writeBinary(writer);
+ case BINARY:
+ if (preWrite(writer, obj)) {
+ try {
+ if (serializer != null)
+ serializer.writeBinary(obj, writer);
+ else
+ ((Binarylizable)obj).writeBinary(writer);
- postWrite(writer);
+ postWrite(writer);
- // Check whether we need to update metadata.
- // The reason for this check is described in https://issues.apache.org/jira/browse/IGNITE-7138.
- if (obj.getClass() != BinaryMetadata.class && obj.getClass() != BinaryTreeMap.class) {
- int schemaId = writer.schemaId();
+ // Check whether we need to update metadata.
+ // The reason for this check is described in https://issues.apache.org/jira/browse/IGNITE-7138.
+ if (obj.getClass() != BinaryMetadata.class && obj.getClass() != BinaryTreeMap.class) {
+ int schemaId = writer.schemaId();
- if (schemaReg.schema(schemaId) == null) {
- // This is new schema, let's update metadata.
- BinaryMetadataCollector collector =
- new BinaryMetadataCollector(typeId, typeName, mapper);
+ if (schemaReg.schema(schemaId) == null) {
+ // This is new schema, let's update metadata.
+ BinaryMetadataCollector collector =
+ new BinaryMetadataCollector(typeId, typeName, mapper);
- if (serializer != null)
- serializer.writeBinary(obj, collector);
- else
- ((Binarylizable)obj).writeBinary(collector);
+ if (serializer != null)
+ serializer.writeBinary(obj, collector);
+ else
+ ((Binarylizable)obj).writeBinary(collector);
- BinarySchema newSchema = collector.schema();
+ BinarySchema newSchema = collector.schema();
- BinaryMetadata meta = new BinaryMetadata(typeId, typeName, collector.meta(),
- affKeyFieldName, Collections.singleton(newSchema), false, null);
+ BinaryMetadata meta = new BinaryMetadata(typeId, typeName, collector.meta(),
+ affKeyFieldName, Collections.singleton(newSchema), false, null);
- ctx.updateMetadata(typeId, meta);
+ ctx.updateMetadata(typeId, meta);
- schemaReg.addSchema(newSchema.schemaId(), newSchema);
+ schemaReg.addSchema(newSchema.schemaId(), newSchema);
+ }
}
- }
- postWriteHashCode(writer, obj);
- }
- finally {
- writer.popSchema();
+ postWriteHashCode(writer, obj);
+ }
+ finally {
+ writer.popSchema();
+ }
}
- }
- break;
+ break;
- case OBJECT:
- if (userType && !stableSchemaPublished) {
- // Update meta before write object with new schema
- BinaryMetadata meta = new BinaryMetadata(typeId, typeName, stableFieldsMeta,
- affKeyFieldName, Collections.singleton(stableSchema), false, null);
+ case OBJECT:
+ if (userType && !stableSchemaPublished) {
+ // Update meta before write object with new schema
+ BinaryMetadata meta = new BinaryMetadata(typeId, typeName, stableFieldsMeta,
+ affKeyFieldName, Collections.singleton(stableSchema), false, null);
- ctx.updateMetadata(typeId, meta);
+ ctx.updateMetadata(typeId, meta);
- schemaReg.addSchema(stableSchema.schemaId(), stableSchema);
+ schemaReg.addSchema(stableSchema.schemaId(), stableSchema);
- stableSchemaPublished = true;
- }
+ stableSchemaPublished = true;
+ }
- if (preWrite(writer, obj)) {
- try {
- for (BinaryFieldAccessor info : fields)
- info.write(obj, writer);
+ if (preWrite(writer, obj)) {
+ try {
+ for (BinaryFieldAccessor info : fields)
+ info.write(obj, writer);
- writer.schemaId(stableSchema.schemaId());
+ writer.schemaId(stableSchema.schemaId());
- postWrite(writer);
- postWriteHashCode(writer, obj);
- }
- finally {
- writer.popSchema();
+ postWrite(writer);
+ postWriteHashCode(writer, obj);
+ }
+ finally {
+ writer.popSchema();
+ }
}
- }
- break;
+ break;
- default:
- assert false : "Invalid mode: " + mode;
+ default:
+ assert false : "Invalid mode: " + mode;
+ }
+ }
+ catch (Exception e) {
+ String msg;
+
+ if (S.INCLUDE_SENSITIVE && !F.isEmpty(typeName))
+ msg = "Failed to serialize object [typeName=" + typeName + ']';
+ else
+ msg = "Failed to serialize object [typeId=" + typeId + ']';
+
+ U.error(ctx.log(), msg, e);
+
+ throw new BinaryObjectException(msg, e);
}
}
@@ -871,10 +885,16 @@ public class BinaryClassDescriptor {
return res;
}
catch (Exception e) {
+ String msg;
+
if (S.INCLUDE_SENSITIVE && !F.isEmpty(typeName))
- throw new BinaryObjectException("Failed to deserialize object [typeName=" + typeName + ']', e);
+ msg = "Failed to deserialize object [typeName=" + typeName + ']';
else
- throw new BinaryObjectException("Failed to deserialize object [typeId=" + typeId + ']', e);
+ msg = "Failed to deserialize object [typeId=" + typeId + ']';
+
+ U.error(ctx.log(), msg, e);
+
+ throw new BinaryObjectException(msg, e);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c533e2cc/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
index 567bee1..3277403 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
@@ -150,7 +150,26 @@ public abstract class BinaryFieldAccessor {
* @param writer Writer.
* @throws BinaryObjectException If failed.
*/
- public abstract void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException;
+ public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ try {
+ write0(obj, writer);
+ }
+ catch (Exception ex) {
+ if (S.INCLUDE_SENSITIVE && !F.isEmpty(name))
+ throw new BinaryObjectException("Failed to write field [name=" + name + ']', ex);
+ else
+ throw new BinaryObjectException("Failed to write field [id=" + id + ']', ex);
+ }
+ }
+
+ /**
+ * Write field.
+ *
+ * @param obj Object.
+ * @param writer Writer.
+ * @throws BinaryObjectException If failed.
+ */
+ protected abstract void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException;
/**
* Read field.
@@ -215,7 +234,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ @Override protected void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
writer.writeFieldIdNoSchemaUpdate(id);
byte val = GridUnsafe.getByteField(obj, offset);
@@ -224,7 +243,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+ @Override protected void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
byte val = reader.readByte(id);
GridUnsafe.putByteField(obj, offset, val);
@@ -245,7 +264,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ @Override protected void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
writer.writeFieldIdNoSchemaUpdate(id);
boolean val = GridUnsafe.getBooleanField(obj, offset);
@@ -254,7 +273,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+ @Override protected void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
boolean val = reader.readBoolean(id);
GridUnsafe.putBooleanField(obj, offset, val);
@@ -275,7 +294,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ @Override protected void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
writer.writeFieldIdNoSchemaUpdate(id);
short val = GridUnsafe.getShortField(obj, offset);
@@ -284,7 +303,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+ @Override protected void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
short val = reader.readShort(id);
GridUnsafe.putShortField(obj, offset, val);
@@ -305,7 +324,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ @Override protected void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
writer.writeFieldIdNoSchemaUpdate(id);
char val = GridUnsafe.getCharField(obj, offset);
@@ -314,7 +333,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+ @Override protected void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
char val = reader.readChar(id);
GridUnsafe.putCharField(obj, offset, val);
@@ -335,7 +354,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ @Override protected void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
writer.writeFieldIdNoSchemaUpdate(id);
int val = GridUnsafe.getIntField(obj, offset);
@@ -344,7 +363,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+ @Override protected void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
int val = reader.readInt(id);
GridUnsafe.putIntField(obj, offset, val);
@@ -365,7 +384,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ @Override protected void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
writer.writeFieldIdNoSchemaUpdate(id);
long val = GridUnsafe.getLongField(obj, offset);
@@ -374,7 +393,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+ @Override protected void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
long val = reader.readLong(id);
GridUnsafe.putLongField(obj, offset, val);
@@ -395,7 +414,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ @Override protected void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
writer.writeFieldIdNoSchemaUpdate(id);
float val = GridUnsafe.getFloatField(obj, offset);
@@ -404,7 +423,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+ @Override protected void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
float val = reader.readFloat(id);
GridUnsafe.putFloatField(obj, offset, val);
@@ -425,7 +444,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ @Override protected void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
writer.writeFieldIdNoSchemaUpdate(id);
double val = GridUnsafe.getDoubleField(obj, offset);
@@ -434,7 +453,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+ @Override protected void read0(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
double val = reader.readDouble(id);
GridUnsafe.putDoubleField(obj, offset, val);
@@ -466,7 +485,7 @@ public abstract class BinaryFieldAccessor {
}
/** {@inheritDoc} */
- @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+ @Override protected void write0(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
assert obj != null;
assert writer != null;
@@ -483,17 +502,17 @@ public abstract class BinaryFieldAccessor {
switch (mode(val)) {
case BYTE:
- writer.writeByteField((Byte) val);
+ writer.writeByteField((Byte)val);
break;
case SHORT:
- writer.writeShortField((Short) val);
+ writer.writeShortField((Short)val);
break;
case INT:
- writer.writeIntField((Integer) val);
+ writer.writeIntField((Integer)val);
break;
http://git-wip-us.apache.org/repos/asf/ignite/blob/c533e2cc/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectInputStream.java
index 0bd7cc0..17eba66 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectInputStream.java
@@ -342,7 +342,13 @@ class OptimizedObjectInputStream extends ObjectInputStream {
curCls = desc.describedClass();
- return desc.read(this);
+ try {
+ return desc.read(this);
+ }
+ catch (IOException e){
+ throw new IOException("Failed to deserialize object [typeName=" +
+ desc.describedClass().getName() + ']', e);
+ }
default:
SB msg = new SB("Unexpected error occurred during unmarshalling");
@@ -443,76 +449,81 @@ class OptimizedObjectInputStream extends ObjectInputStream {
for (int i = 0; i < fieldOffs.size(); i++) {
OptimizedClassDescriptor.FieldInfo t = fieldOffs.get(i);
- switch ((t.type())) {
- case BYTE:
- byte resByte = readByte();
+ try {
+ switch ((t.type())) {
+ case BYTE:
+ byte resByte = readByte();
- if (t.field() != null)
- setByte(obj, t.offset(), resByte);
+ if (t.field() != null)
+ setByte(obj, t.offset(), resByte);
- break;
+ break;
- case SHORT:
- short resShort = readShort();
+ case SHORT:
+ short resShort = readShort();
- if (t.field() != null)
- setShort(obj, t.offset(), resShort);
+ if (t.field() != null)
+ setShort(obj, t.offset(), resShort);
- break;
+ break;
- case INT:
- int resInt = readInt();
+ case INT:
+ int resInt = readInt();
- if (t.field() != null)
- setInt(obj, t.offset(), resInt);
+ if (t.field() != null)
+ setInt(obj, t.offset(), resInt);
- break;
+ break;
- case LONG:
- long resLong = readLong();
+ case LONG:
+ long resLong = readLong();
- if (t.field() != null)
- setLong(obj, t.offset(), resLong);
+ if (t.field() != null)
+ setLong(obj, t.offset(), resLong);
- break;
+ break;
- case FLOAT:
- float resFloat = readFloat();
+ case FLOAT:
+ float resFloat = readFloat();
- if (t.field() != null)
- setFloat(obj, t.offset(), resFloat);
+ if (t.field() != null)
+ setFloat(obj, t.offset(), resFloat);
- break;
+ break;
- case DOUBLE:
- double resDouble = readDouble();
+ case DOUBLE:
+ double resDouble = readDouble();
- if (t.field() != null)
- setDouble(obj, t.offset(), resDouble);
+ if (t.field() != null)
+ setDouble(obj, t.offset(), resDouble);
- break;
+ break;
- case CHAR:
- char resChar = readChar();
+ case CHAR:
+ char resChar = readChar();
- if (t.field() != null)
- setChar(obj, t.offset(), resChar);
+ if (t.field() != null)
+ setChar(obj, t.offset(), resChar);
- break;
+ break;
- case BOOLEAN:
- boolean resBoolean = readBoolean();
+ case BOOLEAN:
+ boolean resBoolean = readBoolean();
- if (t.field() != null)
- setBoolean(obj, t.offset(), resBoolean);
+ if (t.field() != null)
+ setBoolean(obj, t.offset(), resBoolean);
- break;
+ break;
- case OTHER:
- Object resObject = readObject();
+ case OTHER:
+ Object resObject = readObject();
- if (t.field() != null)
- setObject(obj, t.offset(), resObject);
+ if (t.field() != null)
+ setObject(obj, t.offset(), resObject);
+ }
+ }
+ catch (IOException e) {
+ throw new IOException("Failed to deserialize field [name=" + t.name() + ']', e);
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c533e2cc/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
index 8a323a7..66da2da 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectOutputStream.java
@@ -230,12 +230,19 @@ class OptimizedObjectOutputStream extends ObjectOutputStream {
mapper);
}
- if (handle >= 0) {
- writeByte(HANDLE);
- writeInt(handle);
+ try {
+ if (handle >= 0) {
+ writeByte(HANDLE);
+
+ writeInt(handle);
+ }
+ else
+ desc.write(this, obj);
+ }
+ catch (IOException e){
+ throw new IOException("Failed to serialize object [typeName=" +
+ desc.describedClass().getName() + ']', e);
}
- else
- desc.write(this, obj);
}
}
}
@@ -476,58 +483,63 @@ class OptimizedObjectOutputStream extends ObjectOutputStream {
for (int i = 0; i < fields.size(); i++) {
OptimizedClassDescriptor.FieldInfo t = fields.get(i);
- switch (t.type()) {
- case BYTE:
- if (t.field() != null)
- writeByte(getByte(obj, t.offset()));
+ try {
+ switch (t.type()) {
+ case BYTE:
+ if (t.field() != null)
+ writeByte(getByte(obj, t.offset()));
- break;
+ break;
- case SHORT:
- if (t.field() != null)
- writeShort(getShort(obj, t.offset()));
+ case SHORT:
+ if (t.field() != null)
+ writeShort(getShort(obj, t.offset()));
- break;
+ break;
- case INT:
- if (t.field() != null)
- writeInt(getInt(obj, t.offset()));
+ case INT:
+ if (t.field() != null)
+ writeInt(getInt(obj, t.offset()));
- break;
+ break;
- case LONG:
- if (t.field() != null)
- writeLong(getLong(obj, t.offset()));
+ case LONG:
+ if (t.field() != null)
+ writeLong(getLong(obj, t.offset()));
- break;
+ break;
- case FLOAT:
- if (t.field() != null)
- writeFloat(getFloat(obj, t.offset()));
+ case FLOAT:
+ if (t.field() != null)
+ writeFloat(getFloat(obj, t.offset()));
- break;
+ break;
- case DOUBLE:
- if (t.field() != null)
- writeDouble(getDouble(obj, t.offset()));
+ case DOUBLE:
+ if (t.field() != null)
+ writeDouble(getDouble(obj, t.offset()));
- break;
+ break;
- case CHAR:
- if (t.field() != null)
- writeChar(getChar(obj, t.offset()));
+ case CHAR:
+ if (t.field() != null)
+ writeChar(getChar(obj, t.offset()));
- break;
+ break;
- case BOOLEAN:
- if (t.field() != null)
- writeBoolean(getBoolean(obj, t.offset()));
+ case BOOLEAN:
+ if (t.field() != null)
+ writeBoolean(getBoolean(obj, t.offset()));
- break;
+ break;
- case OTHER:
- if (t.field() != null)
- writeObject0(getObject(obj, t.offset()));
+ case OTHER:
+ if (t.field() != null)
+ writeObject0(getObject(obj, t.offset()));
+ }
+ }
+ catch (IOException e) {
+ throw new IOException("Failed to serialize field [name=" + t.name() + ']', e);
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c533e2cc/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java
index a3ee93a..0a10fe7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectExceptionSelfTest.java
@@ -24,6 +24,9 @@ import java.util.UUID;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.binary.BinaryBasicNameMapper;
import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
import org.apache.ignite.configuration.BinaryConfiguration;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
@@ -149,6 +152,44 @@ public class BinaryObjectExceptionSelfTest extends GridCommonAbstractTest {
assertEquals("Fields count must match \"Unexpected field type\" exception count", fields.length, unexpectedCnt);
}
+ /**
+ * Test verbose logging of object marshalling.
+ *
+ * @throws Exception If failed.
+ */
+ 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"));
+ }
+ }
+
+ /** */
+ private static class Value1{
+ /** */
+ Value2 objVal = new Value2();
+
+ /** */
+ static class Value2 implements Binarylizable {
+ /** */
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ throw new RuntimeException("bad object");
+ }
+
+ /** */
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ throw new RuntimeException("bad object");
+ }
+ }
+ }
+
/** */
private enum EnumValues {
/** */
http://git-wip-us.apache.org/repos/asf/ignite/blob/c533e2cc/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamSelfTest.java
index ed0862b..5efc5b9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/marshaller/optimized/OptimizedObjectStreamSelfTest.java
@@ -56,6 +56,7 @@ import java.util.TreeSet;
import java.util.UUID;
import java.util.Vector;
import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.util.io.GridUnsafeDataInput;
@@ -67,7 +68,6 @@ import org.apache.ignite.marshaller.MarshallerExclusions;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
import org.jetbrains.annotations.Nullable;
-import java.util.concurrent.ConcurrentHashMap;
import static org.junit.Assert.assertArrayEquals;
@@ -146,13 +146,9 @@ public class OptimizedObjectStreamSelfTest extends GridCommonAbstractTest {
* @throws Exception If failed.
*/
public void testBoolean() throws Exception {
- boolean val = true;
-
- assertEquals(new Boolean(val), marshalUnmarshal(val));
-
- val = false;
+ assertEquals(Boolean.TRUE, marshalUnmarshal(Boolean.TRUE));
- assertEquals(new Boolean(val), marshalUnmarshal(val));
+ assertEquals(Boolean.FALSE, marshalUnmarshal(Boolean.FALSE));
}
/**
@@ -275,6 +271,49 @@ public class OptimizedObjectStreamSelfTest extends GridCommonAbstractTest {
}
/**
+ * Test informative exception message while failed object unmarshalling
+ *
+ * @throws Exception If failed.
+ */
+ public void testFailedUnmarshallingLogging() throws Exception {
+ OptimizedMarshaller marsh = new OptimizedMarshaller(true);
+
+ marsh.setContext(CTX);
+
+ try {
+ marsh.unmarshal(marsh.marshal(new BadDeserializableObject()), null);
+ }
+ catch (IgniteCheckedException ex) {
+ assertTrue(ex.getCause().getMessage().contains(
+ "object [typeName=org.apache.ignite.internal.marshaller.optimized.OptimizedObjectStreamSelfTest$BadDeserializableObject]"));
+
+ assertTrue(ex.getCause().getCause().getMessage().contains("field [name=val"));
+ }
+ }
+
+
+ /**
+ * Test informative exception message while failed object marshalling
+ *
+ * @throws Exception If failed.
+ */
+ public void testFailedMarshallingLogging() throws Exception {
+ OptimizedMarshaller marsh = new OptimizedMarshaller(true);
+
+ marsh.setContext(CTX);
+
+ try {
+ marsh.marshal(new BadSerializableObject());
+ }
+ catch (IgniteCheckedException ex) {
+ assertTrue(ex.getCause().getMessage().contains(
+ "object [typeName=org.apache.ignite.internal.marshaller.optimized.OptimizedObjectStreamSelfTest$BadSerializableObject]"));
+
+ assertTrue(ex.getCause().getCause().getMessage().contains("field [name=val"));
+ }
+ }
+
+ /**
* @throws Exception If failed.
*/
public void testPool() throws Exception {
@@ -1028,7 +1067,7 @@ public class OptimizedObjectStreamSelfTest extends GridCommonAbstractTest {
marshalUnmarshal(new CustomWriteObjectMethodObject("test"));
}
catch (IOException e) {
- assert e.getCause() instanceof NotActiveException;
+ assert e.getCause().getCause() instanceof NotActiveException;
}
}
@@ -2249,4 +2288,43 @@ public class OptimizedObjectStreamSelfTest extends GridCommonAbstractTest {
return res;
}
}
+
+ /** */
+ static class BadDeserializableObject implements Serializable {
+ /** */
+ BadDeserializableValue val = new BadDeserializableValue();
+ }
+
+ /** */
+ static class BadDeserializableValue implements Serializable {
+ /** */
+ private void writeObject(ObjectOutputStream os) throws IOException{
+ os.write(10);
+ }
+
+ /** */
+ private void readObject(ObjectInputStream os){
+ throw new RuntimeException("bad object");
+ }
+ }
+
+ /** */
+ static class BadSerializableObject implements Serializable {
+ /** */
+ BadSerializableValue val = new BadSerializableValue();
+ }
+
+ /** */
+ static class BadSerializableValue implements Serializable {
+ /** */
+ private void writeObject(ObjectOutputStream os){
+ throw new RuntimeException("bad object");
+ }
+
+ /** */
+ private void readObject(ObjectInputStream os){
+ throw new RuntimeException("bad object");
+ }
+ }
+
}
\ No newline at end of file