WICKET-4812 Make SerializationChecker easier for extending so custom checks can 
be added to it


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

Branch: refs/heads/master
Commit: 5e8c3ddcd1886851a411326e5cf40fb6fcfd4548
Parents: 137f250
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Thu Oct 11 11:43:44 2012 +0300
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Thu Oct 11 11:43:44 2012 +0300

----------------------------------------------------------------------
 .../wicket/core/util/io/SerializableChecker.java   |    7 +-
 .../core/util/objects/checker/IObjectChecker.java  |   16 ++++
 .../objects/checker/NotDetachedModelChecker.java   |   16 ++++
 .../core/util/objects/checker/ObjectChecker.java   |   64 ++++++---------
 .../wicket/serialize/java/JavaSerializerTest.java  |   16 ++++
 .../wicket/util/io/SerializableCheckerTest.java    |   26 +-----
 6 files changed, 79 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/5e8c3ddc/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 fb15cbc..6e5c298 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
@@ -39,15 +39,12 @@ public class SerializableChecker extends ObjectChecker
 {
        /**
         * Exception that is thrown when a non-serializable object was found.
-        * @deprecated Use ObjectChecker.WicketNotSerializableException instead
         */
-       // TODO Wicket 7.0 - remove this class. It is here only for backward 
binary compatibility
-       @Deprecated
-       public static final class WicketNotSerializableException extends 
ObjectChecker.WicketNotSerializableException
+       public static final class WicketNotSerializableException extends 
ObjectCheckException
        {
                private static final long serialVersionUID = 1L;
 
-               WicketNotSerializableException(String message, Throwable cause)
+               private WicketNotSerializableException(String message, 
Throwable cause)
                {
                        super(message, cause);
                }

http://git-wip-us.apache.org/repos/asf/wicket/blob/5e8c3ddc/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/IObjectChecker.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/IObjectChecker.java
 
b/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/IObjectChecker.java
index 85ff014..b9d935d 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/IObjectChecker.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/IObjectChecker.java
@@ -1,3 +1,19 @@
+/*
+ * 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 org.apache.wicket.util.lang.Args;

http://git-wip-us.apache.org/repos/asf/wicket/blob/5e8c3ddc/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/NotDetachedModelChecker.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/NotDetachedModelChecker.java
 
b/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/NotDetachedModelChecker.java
index 969a00a..21fc0c0 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/NotDetachedModelChecker.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/NotDetachedModelChecker.java
@@ -1,3 +1,19 @@
+/*
+ * 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 org.apache.wicket.model.LoadableDetachableModel;

http://git-wip-us.apache.org/repos/asf/wicket/blob/5e8c3ddc/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectChecker.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectChecker.java
 
b/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectChecker.java
index 9a16196..ab328d1 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectChecker.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/core/util/objects/checker/ObjectChecker.java
@@ -1,3 +1,19 @@
+/*
+ * 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.Externalizable;
@@ -42,11 +58,6 @@ public class ObjectChecker extends ObjectOutputStream
 
        public static class ObjectCheckException extends WicketRuntimeException
        {
-               public ObjectCheckException(String message)
-               {
-                       super(message);
-               }
-
                public ObjectCheckException(String message, Throwable cause)
                {
                        super(message, cause);
@@ -54,19 +65,6 @@ public class ObjectChecker extends ObjectOutputStream
        }
 
        /**
-        * Exception that is thrown when a non-serializable object was found.
-        */
-       public static class WicketNotSerializableException extends 
WicketRuntimeException
-       {
-               private static final long serialVersionUID = 1L;
-
-               protected WicketNotSerializableException(String message, 
Throwable cause)
-               {
-                       super(message, cause);
-               }
-       }
-
-       /**
         * Does absolutely nothing.
         */
        private static class NoopOutputStream extends OutputStream
@@ -190,7 +188,6 @@ public class ObjectChecker extends ObjectOutputStream
 
                TraceSlot(Object object, String fieldDescription)
                {
-                       super();
                        this.object = object;
                        this.fieldDescription = fieldDescription;
                }
@@ -282,7 +279,7 @@ public class ObjectChecker extends ObjectOutputStream
                return available;
        }
 
-       /** object stack that with the trace path. */
+       /** object stack with the trace path. */
        private final LinkedList<TraceSlot> traceStack = new 
LinkedList<TraceSlot>();
 
        /** set for checking circular references. */
@@ -371,18 +368,9 @@ public class ObjectChecker extends ObjectOutputStream
                        IObjectChecker.Result result = checker.check(obj);
                        if (result.status == 
IObjectChecker.Result.Status.FAILURE)
                        {
-                               ObjectCheckException ocx;
                                String prettyPrintMessage = 
toPrettyPrintedStack(Classes.name(cls));
                                String exceptionMessage = result.reason + '\n' 
+ prettyPrintMessage;
-                               if (result.cause != null)
-                               {
-                                       ocx = new 
ObjectCheckException(exceptionMessage, result.cause);
-                               }
-                               else
-                               {
-                                       ocx = new 
ObjectCheckException(exceptionMessage);
-                               }
-                               throw ocx;
+                               throw new 
ObjectCheckException(exceptionMessage, result.cause);
                        }
                }
 
@@ -460,11 +448,11 @@ public class ObjectChecker extends ObjectOutputStream
                        }
                        catch (Exception e)
                        {
-                               if (e instanceof WicketNotSerializableException)
+                               if (e instanceof ObjectCheckException)
                                {
-                                       throw (WicketNotSerializableException)e;
+                                       throw (ObjectCheckException)e;
                                }
-                               log.warn("error delegating to Externalizable : 
{}, path: {}", e.getMessage(), currentPath());
+                               log.warn("Error delegating to Externalizable : 
{}, path: {}", e.getMessage(), currentPath());
                        }
                }
                else
@@ -532,9 +520,9 @@ public class ObjectChecker extends ObjectOutputStream
                                }
                                catch (Exception e)
                                {
-                                       if (e instanceof 
WicketNotSerializableException)
+                                       if (e instanceof ObjectCheckException)
                                        {
-                                               throw 
(WicketNotSerializableException)e;
+                                               throw (ObjectCheckException)e;
                                        }
                                        log.warn("error delegating to 
writeObject : {}, path: {}", e.getMessage(), currentPath());
                                }
@@ -671,8 +659,8 @@ public class ObjectChecker extends ObjectOutputStream
         */
        protected final String toPrettyPrintedStack(String type)
        {
-               StringBuilder result = new StringBuilder();
-               StringBuilder spaces = new StringBuilder();
+               StringBuilder result = new StringBuilder(512);
+               StringBuilder spaces = new StringBuilder(32);
                result.append("A problem occurred while checking object with 
type: ");
                result.append(type);
                result.append("\nField hierarchy is:");
@@ -680,7 +668,7 @@ public class ObjectChecker extends ObjectOutputStream
                {
                        spaces.append(' ').append(' ');
                        
result.append('\n').append(spaces).append(slot.fieldDescription);
-                       result.append(" 
[class=").append(slot.object.getClass().getName());
+                       result.append(" 
[class=").append(Classes.name(slot.object.getClass()));
                        if (slot.object instanceof Component)
                        {
                                Component component = (Component)slot.object;

http://git-wip-us.apache.org/repos/asf/wicket/blob/5e8c3ddc/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 31086b3..f599c61 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
@@ -1,3 +1,19 @@
+/*
+ * 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.serialize.java;
 
 import java.io.IOException;

http://git-wip-us.apache.org/repos/asf/wicket/blob/5e8c3ddc/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 2190b38..bb72bed 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
@@ -24,7 +24,7 @@ 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.io.SerializableChecker.WicketNotSerializableException;
+import org.apache.wicket.core.util.objects.checker.ObjectChecker;
 import org.apache.wicket.util.Log4jEventHistory;
 import org.apache.wicket.util.value.ValueMap;
 import org.junit.Assert;
@@ -58,7 +58,7 @@ public class SerializableCheckerTest extends Assert
        @Test
        public void runtimeExceptionTolerance() throws IOException
        {
-               Logger logger = LogManager.getLogger(SerializableChecker.class);
+               Logger logger = LogManager.getLogger(ObjectChecker.class);
                logger.setLevel(Level.WARN);
                Log4jEventHistory logHistory = new Log4jEventHistory();
                logger.addAppender(logHistory);
@@ -67,7 +67,7 @@ public class SerializableCheckerTest extends Assert
                try
                {
                        serializableChecker.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";
+                       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));
                }
                catch (TestException notMeaningfulException)
@@ -76,26 +76,6 @@ public class SerializableCheckerTest extends Assert
                }
        }
 
-       /**
-        * @throws IOException
-        */
-       @Test
-       public void nonSerializableTypeDetection() throws IOException
-       {
-               SerializableChecker serializableChecker = new 
SerializableChecker(
-                       new NotSerializableException());
-               String exceptionMessage = null;
-               try
-               {
-                       serializableChecker.writeObject(new TestType2());
-               }
-               catch (WicketNotSerializableException e)
-               {
-                       exceptionMessage = e.getMessage();
-               }
-               
assertTrue(exceptionMessage.contains(NonSerializableType.class.getName()));
-       }
-
        private static class TestType1 implements Serializable
        {
                private static final long serialVersionUID = 1L;

Reply via email to