From 8e8f30623a11211a153828b8105a63f3ffc81917 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 30 Sep 2011 08:21:07 +0000 Subject: [PATCH] #7697 SQLContainer.containsId logs a ClassCastException svn changeset:21463/svn branch:6.7 --- .../data/util/sqlcontainer/SQLContainer.java | 2 +- .../util/sqlcontainer/SQLContainerTest.java | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java index f6b22bfecb..009a7d5e63 100644 --- a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java +++ b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java @@ -210,7 +210,7 @@ public class SQLContainer implements Container, Container.Filterable, return rowNum >= 0 && rowNum < size; } - if (!(itemId instanceof TemporaryRowId)) { + if (itemId instanceof RowId && !(itemId instanceof TemporaryRowId)) { try { return delegate.containsRowWithKey(((RowId) itemId).getId()); } catch (Exception e) { diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java index d82909041f..6b3aed3203 100644 --- a/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java +++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java @@ -7,6 +7,9 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.logging.Handler; +import java.util.logging.LogRecord; +import java.util.logging.Logger; import org.easymock.EasyMock; import org.easymock.IAnswer; @@ -813,6 +816,31 @@ public class SQLContainerTest { Assert.assertFalse(container.containsId(id)); } + @Test + public void containsId_unknownObject() throws SQLException { + SQLContainer container = new SQLContainer(new FreeformQuery( + "SELECT * FROM people", connectionPool, "ID")); + Logger logger = Logger.getLogger(SQLContainer.class.getName()); + logger.addHandler(new Handler() { + + @Override + public void publish(LogRecord record) { + Assert.fail("No messages should be logged"); + + } + + @Override + public void flush() { + } + + @Override + public void close() throws SecurityException { + } + }); + + Assert.assertFalse(container.containsId(new Object())); + } + @Test public void removeItem_freeformOneAddedItem_removesTheAddedItem() throws SQLException { -- 2.39.5