You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2018/06/12 17:55:37 UTC

[1/2] wicket git commit: WICKET-6560 no warning for null

Repository: wicket
Updated Branches:
  refs/heads/wicket-8.x d2ad5d333 -> 48468a1b0


WICKET-6560 no warning for null


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

Branch: refs/heads/wicket-8.x
Commit: cb74db16d017216ca52b7876ac8ac11bf7a3be39
Parents: d2ad5d3
Author: Sven Meier <sv...@apache.org>
Authored: Sun Jun 10 22:33:58 2018 +0200
Committer: Sven Meier <sv...@apache.org>
Committed: Tue Jun 12 19:52:20 2018 +0200

----------------------------------------------------------------------
 .../org/apache/wicket/model/ChainingModel.java  |   2 +-
 .../apache/wicket/model/ChainingModelTest.java  | 103 +++++++++++++++++++
 2 files changed, 104 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/cb74db16/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
index fa0ca7a..4b65b76 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
@@ -48,7 +48,7 @@ public class ChainingModel<T> implements IChainingModel<T>
 					+ "in models directly as it may lead to serialization problems. "
 					+ "If you need to access a property of the session via the model use the "
 					+ "page instance as the model object and 'session.attribute' as the path.");
-		} else if (modelObject instanceof Serializable == false)
+		} else if (modelObject != null && (modelObject instanceof Serializable == false))
 		{
 			LOG.warn("It is not a good idea to reference a non-serializable instance "
 					+ "in models directly as it may lead to serialization problems.");

http://git-wip-us.apache.org/repos/asf/wicket/blob/cb74db16/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
new file mode 100644
index 0000000..6b64d44
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test for {@link ChainingModel}.
+ * 
+ * @author svenmeier
+ */
+public class ChainingModelTest
+{
+	@Test
+	public void testNonModel() {
+		ChainingModel<Integer> model = new ChainingModel<>(1);
+		
+		assertEquals(Integer.valueOf(1), model.getObject());
+		model.setObject(2);
+		assertEquals(Integer.valueOf(2), model.getObject());
+	}
+	
+	@Test
+	public void testDetachable() {
+		class TestDetachable implements IDetachable
+		{
+			boolean detached = false;
+			
+			@Override
+			public void detach()
+			{
+				detached = true;
+			}
+		};
+		TestDetachable test = new TestDetachable();
+		
+		ChainingModel<TestDetachable> model = new ChainingModel<>(test);
+		assertSame(test,  model.getObject());
+
+		test = new TestDetachable();
+		model.setObject(test);
+		assertSame(test,  model.getObject());
+
+		model.detach();
+		assertTrue(test.detached);
+	}
+
+	@Test
+	public void testModel() {
+		class TestModel implements IModel<Integer>
+		{
+			boolean detached = false;
+			int value = 1;
+			
+			@Override
+			public Integer getObject()
+			{
+				return value;
+			}
+			
+			@Override
+			public void setObject(Integer object)
+			{
+				this.value = object;
+			}
+			
+			@Override
+			public void detach()
+			{
+				detached = true;
+			}
+		};
+		TestModel test = new TestModel();
+		
+		ChainingModel<Integer> model = new ChainingModel<>(test);
+		
+		assertEquals(Integer.valueOf(1), model.getObject());
+
+		model.setObject(2);
+		assertEquals(2, test.value);
+		
+		model.detach();
+		assertTrue(test.detached);
+	}
+}
\ No newline at end of file


[2/2] wicket git commit: WICKET-6560 log class of non serializable

Posted by sv...@apache.org.
WICKET-6560 log class of non serializable


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

Branch: refs/heads/wicket-8.x
Commit: 48468a1b00773ac945f212adf8563063f6b4e31d
Parents: cb74db1
Author: Sven Meier <sv...@apache.org>
Authored: Mon Jun 11 23:09:41 2018 +0200
Committer: Sven Meier <sv...@apache.org>
Committed: Tue Jun 12 19:52:30 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/wicket/model/ChainingModel.java   |  4 ++--
 .../org/apache/wicket/model/ChainingModelTest.java    | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/48468a1b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
index 4b65b76..5d5a7fa 100644
--- a/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
+++ b/wicket-core/src/main/java/org/apache/wicket/model/ChainingModel.java
@@ -50,8 +50,8 @@ public class ChainingModel<T> implements IChainingModel<T>
 					+ "page instance as the model object and 'session.attribute' as the path.");
 		} else if (modelObject != null && (modelObject instanceof Serializable == false))
 		{
-			LOG.warn("It is not a good idea to reference a non-serializable instance "
-					+ "in models directly as it may lead to serialization problems.");
+			LOG.warn("It is not a good idea to reference non-serializable {} "
+					+ "in a model directly as it may lead to serialization problems.", modelObject.getClass());
 		}
 
 		target = modelObject;

http://git-wip-us.apache.org/repos/asf/wicket/blob/48468a1b/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java b/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
index 6b64d44..3239136 100644
--- a/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/model/ChainingModelTest.java
@@ -16,10 +16,19 @@
  */
 package org.apache.wicket.model;
 
+import static org.hamcrest.core.StringContains.containsString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
+import java.io.StringWriter;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.SimpleLayout;
+import org.apache.log4j.WriterAppender;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -39,6 +48,11 @@ public class ChainingModelTest
 	}
 	
 	@Test
+	public void testNonSerializable() {
+		new ChainingModel<>(Thread.currentThread());
+	}
+	
+	@Test
 	public void testDetachable() {
 		class TestDetachable implements IDetachable
 		{