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:38:41 UTC

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

Repository: wicket
Updated Branches:
  refs/heads/wicket-6.x 743240ab6 -> 655c82685


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/87f87585
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/87f87585
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/87f87585

Branch: refs/heads/wicket-6.x
Commit: 87f87585326d5e1de8524bd0a7c8ce5b8c760ba0
Parents: 743240a
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Aug 7 11:37:32 2014 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Aug 7 11:37:32 2014 +0200

----------------------------------------------------------------------
 .../org/apache/wicket/core/util/io/SerializableChecker.java   | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/87f87585/wicket-core/src/main/java/org/apache/wicket/core/util/io/SerializableChecker.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/io/SerializableChecker.java b/wicket-core/src/main/java/org/apache/wicket/core/util/io/SerializableChecker.java
index 76c0295..ce2efde 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/io/SerializableChecker.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/io/SerializableChecker.java
@@ -35,6 +35,11 @@ import org.apache.wicket.util.io.ByteArrayOutputStream;
  * to the not-serializable object. The exception is thrown for the first non-serializable instance
  * it encounters, so multiple problems will not be shown.
  *
+ * <p>
+ * Note: There is a system property <em>-Dsun.io.serialization.extendedDebugInfo=true</em> that could give
+ * even more debug information.
+ * </p>
+ *
  * @author eelcohillenius
  * @author Al Maw
  */
@@ -144,4 +149,4 @@ public class SerializableChecker extends CheckingObjectOutputStream
 	{
 		return CheckingObjectOutputStream.isAvailable();
 	}
-}
\ No newline at end of file
+}


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

Posted by mg...@apache.org.
WICKET-5667 Preserve the NotSerializableException if an error occur while using the IObjectCheckers


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

Branch: refs/heads/wicket-6.x
Commit: 655c82685532dbc1536b478c21a5ece7d57ae9f9
Parents: 87f8758
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:38:10 2014 +0200

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


http://git-wip-us.apache.org/repos/asf/wicket/blob/655c8268/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 8c01dc8..d4e35d0 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,11 +263,24 @@ public class JavaSerializer implements ISerializer
 			{
 				if (CheckingObjectOutputStream.isAvailable())
 				{
-					// trigger serialization again, but this time gather
-					// some more info
-					new SerializableChecker(outputStream, nsx).writeObject(obj);
-					// if we get here, we didn't fail, while we
-					// should;
+					try
+					{
+						// trigger serialization again, but this time gather some more info
+						new SerializableChecker(outputStream, nsx).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;
 				}
 				throw nsx;

http://git-wip-us.apache.org/repos/asf/wicket/blob/655c8268/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!");
+		}
+	}
 }