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 2013/05/01 12:05:32 UTC
git commit: WICKET-4817 Remove SerializableChecker and use
CheckingObjectOutputStream + ObjectSerializableChecker
Updated Branches:
refs/heads/master a192429f1 -> d0441059e
WICKET-4817 Remove SerializableChecker and use CheckingObjectOutputStream + ObjectSerializableChecker
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/d0441059
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/d0441059
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/d0441059
Branch: refs/heads/master
Commit: d0441059e0bba325f3f68a5db00282cc3901dc5a
Parents: a192429
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed May 1 12:00:18 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed May 1 12:00:18 2013 +0200
----------------------------------------------------------------------
.../wicket/core/util/io/SerializableChecker.java | 147 ---------------
.../checker/ObjectSerializationChecker.java | 70 +++++++
.../wicket/serialize/java/JavaSerializer.java | 13 +-
.../wicket/util/io/SerializableCheckerTest.java | 17 +-
4 files changed, 86 insertions(+), 161 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/d0441059/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
deleted file mode 100644
index 76c0295..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/io/SerializableChecker.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.core.util.io;
-
-import java.io.IOException;
-import java.io.NotSerializableException;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.lang.reflect.Proxy;
-
-import org.apache.wicket.WicketRuntimeException;
-import org.apache.wicket.core.util.objects.checker.AbstractObjectChecker;
-import org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream;
-import org.apache.wicket.util.io.ByteArrayOutputStream;
-
-
-/**
- * Utility class that analyzes objects for non-serializable nodes. Construct, then call
- * {@link #writeObject(Object)} with the object you want to check. When a non-serializable object is
- * found, a {@link ObjectCheckException} is thrown with a message that shows the trace up
- * to the not-serializable object. The exception is thrown for the first non-serializable instance
- * it encounters, so multiple problems will not be shown.
- *
- * @author eelcohillenius
- * @author Al Maw
- */
-public class SerializableChecker extends CheckingObjectOutputStream
-{
- /**
- * Exception that is thrown when a non-serializable object was found.
- * @deprecated ObjectCheckException is thrown instead
- */
- @Deprecated
- public static final class WicketNotSerializableException extends WicketRuntimeException
- {
- private static final long serialVersionUID = 1L;
-
- private WicketNotSerializableException(String message, Throwable cause)
- {
- super(message, cause);
- }
- }
-
- /**
- * An implementation of IObjectChecker that checks whether the object
- * implements {@link Serializable} interface
- */
- public static class ObjectSerializationChecker extends AbstractObjectChecker
- {
- /** Exception that should be set as the cause when throwing a new exception. */
- private final NotSerializableException cause;
-
- /**
- * A constructor to use when the checker is used before a previous attempt to
- * serialize the object.
- */
- public ObjectSerializationChecker()
- {
- this(null);
- }
-
- /**
- * A constructor to use when there was a previous attempt to serialize the
- * object and it failed with the {@code cause}.
- *
- * @param cause
- * the cause of the serialization failure in a previous attempt.
- */
- public ObjectSerializationChecker(NotSerializableException cause)
- {
- this.cause = cause;
- }
-
- /**
- * Makes the check for all objects. Exclusions by type is not supported.
- * @param object
- * the object to check
- * @return the {@link Result#SUCCESS} if the object can be serialized.
- */
- @Override
- public Result check(Object object)
- {
- Result result = Result.SUCCESS;
- if (!(object instanceof Serializable) && (!Proxy.isProxyClass(object.getClass())))
- {
- result = new Result(Result.Status.FAILURE, "The object type is not Serializable!", cause);
- }
-
- return result;
- }
- }
-
- /**
- * Constructor.
- *
- * @param exception
- * exception that should be set as the cause when throwing a new exception
- *
- * @throws IOException
- */
- public SerializableChecker(NotSerializableException exception) throws IOException
- {
- this(new ByteArrayOutputStream(), exception);
- }
-
- /**
- * Constructor.
- *
- * @param exception
- * exception that should be set as the cause when throwing a new exception
- * @param outputStream
- * the output stream where the serialized object will be written upon successful check
- *
- * @throws IOException
- */
- public SerializableChecker(final OutputStream outputStream, NotSerializableException exception) throws IOException
- {
- super(outputStream, new ObjectSerializationChecker(exception));
- }
-
- /**
- * Delegate to preserve binary compatibility.
- *
- * @return {@code true} if the checker can be used
- * @deprecated Use ObjectChecker#isAvailable() instead
- */
- // TODO Wicket 7.0 - remove this method
- @Deprecated
- public static boolean isAvailable()
- {
- return CheckingObjectOutputStream.isAvailable();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/d0441059/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
new file mode 100644
index 0000000..57bbeba
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectSerializationChecker.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.core.util.objects.checker;
+
+import java.io.NotSerializableException;
+import java.io.Serializable;
+import java.lang.reflect.Proxy;
+
+/**
+ * An implementation of IObjectChecker that checks whether the object
+ * implements {@link java.io.Serializable} interface
+ */
+public class ObjectSerializationChecker extends AbstractObjectChecker
+{
+ /** Exception that should be set as the cause when throwing a new exception. */
+ private final NotSerializableException cause;
+
+ /**
+ * A constructor to use when the checker is used before a previous attempt to
+ * serialize the object.
+ */
+ public ObjectSerializationChecker()
+ {
+ this(null);
+ }
+
+ /**
+ * A constructor to use when there was a previous attempt to serialize the
+ * object and it failed with the {@code cause}.
+ *
+ * @param cause
+ * the cause of the serialization failure in a previous attempt.
+ */
+ public ObjectSerializationChecker(NotSerializableException cause)
+ {
+ this.cause = cause;
+ }
+
+ /**
+ * Makes the check for all objects. Exclusions by type is not supported.
+ * @param object
+ * the object to check
+ * @return the {@link org.apache.wicket.core.util.objects.checker.IObjectChecker.Result#SUCCESS} if the object can be serialized.
+ */
+ @Override
+ public Result check(Object object)
+ {
+ Result result = Result.SUCCESS;
+ if (!(object instanceof Serializable) && (!Proxy.isProxyClass(object.getClass())))
+ {
+ result = new Result(Result.Status.FAILURE, "The object type is not Serializable!", cause);
+ }
+
+ return result;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/wicket/blob/d0441059/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 4096654..12425ba 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
@@ -30,8 +30,8 @@ import org.apache.wicket.Application;
import org.apache.wicket.ThreadContext;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.application.IClassResolver;
-import org.apache.wicket.core.util.io.SerializableChecker;
import org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream;
+import org.apache.wicket.core.util.objects.checker.ObjectSerializationChecker;
import org.apache.wicket.serialize.ISerializer;
import org.apache.wicket.settings.IApplicationSettings;
import org.apache.wicket.util.io.IOUtils;
@@ -263,11 +263,12 @@ 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;
+ // trigger serialization again, but this time gather some more info
+ CheckingObjectOutputStream checkingObjectOutputStream =
+ new CheckingObjectOutputStream(outputStream, new ObjectSerializationChecker(nsx));
+ checkingObjectOutputStream.writeObject(obj);
+
+ // 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/d0441059/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java b/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java
index 879dc75..321c502 100644
--- a/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/util/io/SerializableCheckerTest.java
@@ -23,8 +23,8 @@ import java.io.Serializable;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
-import org.apache.wicket.core.util.io.SerializableChecker;
import org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream;
+import org.apache.wicket.core.util.objects.checker.ObjectSerializationChecker;
import org.apache.wicket.util.Log4jEventHistory;
import org.apache.wicket.util.value.ValueMap;
import org.junit.Assert;
@@ -44,7 +44,8 @@ public class SerializableCheckerTest extends Assert
@Test
public void valueMap() throws IOException
{
- SerializableChecker checker = new SerializableChecker(new ByteArrayOutputStream(), new NotSerializableException());
+ CheckingObjectOutputStream checker = new CheckingObjectOutputStream(new ByteArrayOutputStream(),
+ new ObjectSerializationChecker(new NotSerializableException()));
checker.writeObject(new ValueMap());
}
@@ -62,11 +63,11 @@ public class SerializableCheckerTest extends Assert
logger.setLevel(Level.WARN);
Log4jEventHistory logHistory = new Log4jEventHistory();
logger.addAppender(logHistory);
- SerializableChecker serializableChecker = new SerializableChecker(new ByteArrayOutputStream(),
- new NotSerializableException());
+ CheckingObjectOutputStream checker = new CheckingObjectOutputStream(new ByteArrayOutputStream(),
+ new ObjectSerializationChecker(new NotSerializableException()));
try
{
- serializableChecker.writeObject(new TestType1());
+ checker.writeObject(new TestType1());
String expectedMessage = "Wasn't possible to check the object 'class org.apache.wicket.util.io.SerializableCheckerTest$ProblematicType' possible due an problematic implementation of equals method";
assertTrue(logHistory.contains(Level.WARN, expectedMessage));
}
@@ -82,12 +83,12 @@ public class SerializableCheckerTest extends Assert
@Test
public void nonSerializableTypeDetection() throws IOException
{
- SerializableChecker serializableChecker = new SerializableChecker(new ByteArrayOutputStream(),
- new NotSerializableException());
+ CheckingObjectOutputStream checker = new CheckingObjectOutputStream(new ByteArrayOutputStream(),
+ new ObjectSerializationChecker(new NotSerializableException()));
String exceptionMessage = null;
try
{
- serializableChecker.writeObject(new TestType2());
+ checker.writeObject(new TestType2());
}
catch (CheckingObjectOutputStream.ObjectCheckException e)
{