You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2014/08/07 11:43:17 UTC

[1/2] git commit: WICKET-5667 Preserve the NotSerializableException if an error occur while using the IObjectCheckers

Repository: wicket
Updated Branches:
  refs/heads/master bdf0f9f7a -> f4d819a95


WICKET-5667 Preserve the NotSerializableException if an error occur while using the IObjectCheckers

(cherry picked from commit 655c82685532dbc1536b478c21a5ece7d57ae9f9)


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c904f737
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c904f737
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c904f737

Branch: refs/heads/master
Commit: c904f73756ac956b60a087d218d4f2845725d26c
Parents: bdf0f9f
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Aug 7 11:38:10 2014 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Aug 7 11:41:02 2014 +0200

----------------------------------------------------------------------
 .../wicket/serialize/java/JavaSerializer.java   | 21 ++++-
 .../serialize/java/JavaSerializerTest.java      | 86 ++++++++++++++++++++
 2 files changed, 104 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/c904f737/wicket-core/src/main/java/org/apache/wicket/serialize/java/JavaSerializer.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/serialize/java/JavaSerializer.java b/wicket-core/src/main/java/org/apache/wicket/serialize/java/JavaSerializer.java
index 7e201e2..b670564 100644
--- a/wicket-core/src/main/java/org/apache/wicket/serialize/java/JavaSerializer.java
+++ b/wicket-core/src/main/java/org/apache/wicket/serialize/java/JavaSerializer.java
@@ -263,10 +263,25 @@ public class JavaSerializer implements ISerializer
 			{
 				if (CheckingObjectOutputStream.isAvailable())
 				{
-					// trigger serialization again, but this time gather some more info
-					CheckingObjectOutputStream checkingObjectOutputStream =
+					try
+					{
+						// trigger serialization again, but this time gather some more info
+						CheckingObjectOutputStream checkingObjectOutputStream =
 							new CheckingObjectOutputStream(outputStream, new ObjectSerializationChecker(nsx));
-					checkingObjectOutputStream.writeObject(obj);
+						checkingObjectOutputStream.writeObject(obj);
+					} 
+					catch (Exception x)
+					{
+						if (x instanceof CheckingObjectOutputStream.ObjectCheckException)
+						{
+							throw (CheckingObjectOutputStream.ObjectCheckException) x;
+						}
+						else
+						{
+							x.initCause(nsx);
+							throw new WicketRuntimeException("A problem occurred while trying to collect debug information about not serializable object", x);
+						}
+					}
 
 					// if we get here, we didn't fail, while we should
 					throw nsx;

http://git-wip-us.apache.org/repos/asf/wicket/blob/c904f737/wicket-core/src/test/java/org/apache/wicket/serialize/java/JavaSerializerTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/serialize/java/JavaSerializerTest.java b/wicket-core/src/test/java/org/apache/wicket/serialize/java/JavaSerializerTest.java
index a38e756..c7b48d1 100644
--- a/wicket-core/src/test/java/org/apache/wicket/serialize/java/JavaSerializerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/serialize/java/JavaSerializerTest.java
@@ -16,10 +16,18 @@
  */
 package org.apache.wicket.serialize.java;
 
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.NotSerializableException;
 import java.io.ObjectOutputStream;
 import java.io.OutputStream;
+import java.io.Serializable;
 
+import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.WicketTestCase;
 import org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream;
 import org.apache.wicket.core.util.objects.checker.IObjectChecker;
@@ -27,6 +35,7 @@ import org.apache.wicket.core.util.objects.checker.NotDetachedModelChecker;
 import org.apache.wicket.markup.html.WebComponent;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.util.io.IOUtils;
 import org.junit.Test;
 
 /**
@@ -113,4 +122,81 @@ public class JavaSerializerTest extends WicketTestCase
 		byte[] bytes = serializer.serialize("Something to serialize");
 		assertEquals(57, bytes.length);
 	}
+
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-5667
+	 */
+	@Test
+	public void preserveTheOriginalException()
+	{
+		JavaSerializer serializer = new JavaSerializer("JavaSerializerTest-aa")
+		{
+			// Override serialize to re-throw the exception instead of just logging it
+			// The exception is used later to make the assertions
+			@Override
+			public byte[] serialize(Object object)
+			{
+				try
+				{
+					final ByteArrayOutputStream out = new ByteArrayOutputStream();
+					ObjectOutputStream oos = null;
+					try
+					{
+						oos = newObjectOutputStream(out);
+						oos.writeObject("applicationKey");
+						oos.writeObject(object);
+					}
+					finally
+					{
+						try
+						{
+							IOUtils.close(oos);
+						}
+						finally
+						{
+							out.close();
+						}
+					}
+					return out.toByteArray();
+				}
+				catch (Exception x)
+				{
+					throw new RuntimeException(x);
+				}
+			}
+		};
+		try
+		{
+			serializer.serialize(new ObjectThatBlowsOnSerialization());
+			fail("The serialization should have failed!");
+		}
+		catch (Exception x)
+		{
+			Throwable cause0 = x.getCause();
+			assertThat(cause0, is(instanceOf(WicketRuntimeException.class)));
+			WicketRuntimeException wrx = (WicketRuntimeException) cause0;
+
+			Throwable cause1 = wrx.getCause();
+			assertThat(cause1, is(instanceOf(IllegalStateException.class)));
+			assertThat(cause1.getMessage(), is(equalTo("Cannot serialize me twice!")));
+
+			Throwable cause2 = cause1.getCause();
+			assertThat(cause2, is(instanceOf(NotSerializableException.class)));
+		}
+	}
+
+	private static class ObjectThatBlowsOnSerialization implements Serializable
+	{
+		private int counter = 0;
+
+		private void writeObject(ObjectOutputStream oos) throws IOException
+		{
+			counter++;
+			if (counter == 1)
+			{
+				throw new NotSerializableException();
+			}
+			throw new IllegalStateException("Cannot serialize me twice!");
+		}
+	}
 }


[2/2] git commit: Add a note about -Dsun.io.serialization.extendedDebugInfo

Posted by mg...@apache.org.
Add a note about -Dsun.io.serialization.extendedDebugInfo


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f4d819a9
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f4d819a9
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f4d819a9

Branch: refs/heads/master
Commit: f4d819a959a5a7cc0093035f72c5b5b0cc499194
Parents: c904f73
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Aug 7 11:41:22 2014 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Aug 7 11:41:22 2014 +0200

----------------------------------------------------------------------
 .../core/util/objects/checker/ObjectSerializationChecker.java | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/f4d819a9/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectSerializationChecker.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectSerializationChecker.java b/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectSerializationChecker.java
index 57bbeba..c03438a 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectSerializationChecker.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectSerializationChecker.java
@@ -23,6 +23,11 @@ import java.lang.reflect.Proxy;
 /**
  * An implementation of IObjectChecker that checks whether the object
  * implements {@link java.io.Serializable} interface
+ *
+ * <p>
+ * Note: There is a system property <em>-Dsun.io.serialization.extendedDebugInfo=true</em> that could give
+ * even more debug information.
+ * </p>
  */
 public class ObjectSerializationChecker extends AbstractObjectChecker
 {
@@ -67,4 +72,4 @@ public class ObjectSerializationChecker extends AbstractObjectChecker
 
 		return result;
 	}
-}
\ No newline at end of file
+}